[Plugin] [REL] Math Plugin
#1

This is in a beta / work in progress state (thinking what to add, making test cases, etc..), so current natives contained are - this is the include itself:

MathPlugin.inc 1.1

pawn Код:
// game helpers
    native Float:MPDistanceCameraToLocation(Float:CamX, Float:CamY, Float:CamZ, Float:ObjX, Float:ObjY, Float:ObjZ, Float:FrX, Float:FrY, Float:FrZ); // calculates how distant target aim is from camera data pointed towards a certain point
    native Float:MPGetVehicleUpsideDown(vehicleid); // returns values such as 1.0 as pointing up, -1.0 is totally upside down. returns -5.0 if car id is not 1..2000.
    native MPGetAimTarget(PlayerID, Float:SeekRadius = 50.0); // returns player that this player is aiming at or invalid player id if no player in target area.
    native MPGetTrailerTowingVehicle(vehicleid); // finds the vehicle that this trailer is attached to, returns invalid_vehicle_id if invalid or not attached to any towing vehicle.
    native MPGetVehicleDriver(vehicleid); // gets vehicle driver id or invalid player id - does a quick reverse vehicle to player id lookup.
    native MPGetVehicleDriverCount(vehicleid); // returns number of drivers a car has (important to solve 2 drivers 1 car issue - if you wrote any decent anticheat you know what i mean)
    native MPGetVehicleOccupantCnt(vehicleid); // returns number of player a vehicle is carrying
    native MPGetVehicleSurfersCnt(vehicleid); // returns number of players surfing a vehicle
   
    native MPProjectPointOnVehicle(vehicleid, Float:v1x, Float:v1y, Float:v1z, &Float:resx, &Float:resy, &Float:resz, worldspace = 0); // projects a point on vehicle's rotation on all 3 axes.
    native MPProjectPointOnPlayer(playerid, Float:v1x, Float:v1y, Float:v1z, &Float:resx, &Float:resy, &Float:resz); // projects a point on player's facing angle (x - sideways, y front/back, z = up/down).
   
    // pure math
    native Float:FMPVecLength(Float:v1x, Float:v1y, Float:v1z); // calculates length of a simple XYZ 3d vector (FAST,less precision)
    native Float:MPClamp360(Float:value);
    native Float:MPDistance(Float:v1x, Float:v1y, Float:v1z, Float:v2x, Float:v2y, Float:v2z)// distance between 2 points
    native Float:MPDistancePointLine(Float:PointX, Float:PointY, Float:PointZ, Float:LineSx, Float:LineSy, Float:LineSz, Float:LineEx, Float:LineEy, Float:LineEz); // http://paulbourke.net/geometry/pointline/ returns super huge number 10000000 if outside of range of specified the lie segment.
    native Float:MPDotProduct(Float:v1x, Float:v1y, Float:v1z, Float:v2x, Float:v2y, Float:v2z);
    native Float:MPFDistance(Float:v1x, Float:v1y, Float:v1z, Float:v2x, Float:v2y, Float:v2z); // distance between 2 points (faster but less precise)
    native Float:MPFSQRT(Float:value)// Faster sqrt (****** the 0x5f3759df method)
    native Float:MPVecLength(Float:v1x, Float:v1y, Float:v1z); // calculates length of a simple XYZ 3d vector
    native MPCrossProduct(Float:v1x, Float:v1y, Float:v1z, Float:v2x, Float:v2y, Float:v2z, &Float:resx, &Float:resy, &Float:resz);
    native MPFNormalize(&Float:vx, &Float:vy, &Float:vz); // fast float normalization of a vector to unit-length (makes whatever vector 1.0 long, purely to preserve direction and be able to scale it controllably)
    native MPInterpolatePoint(Float:v1x, Float:v1y, Float:v1z, Float:v2x, Float:v2y, Float:v2z, &Float:resx, &Float:resy, &Float:resz, Float:distance);


    native MPFloatIsFinite(Float:in); // returns 1 if floating point is finite (when it is NOT NaN or INF)
    native Float:MPFiniteFloat(Float:in, Float:alternative = 0.0); // returns the same floating point as received, but if the number is not finite (INF / NaN) it will return the second parameter.
   
    native Float:MPReturnInf(positive); // returns a invalid float - infinite (+inf / -inf)
    native Float:MPReturnNan(positive); // returns a invalid float - NaN (+NaN / -NaN)
There's some advanced stuff.

I'm sure everyone will appreciate the benefits of running this in native C code for greater speed and convinience of the new functions.

I am building this extra auxilary math plugin for sa-mp servers, I'm also accepting (serious, realistic) ideas on what you guys use a lot and is really tedious ( in similar philosophy like MPGetVehicleDriver reverse lookup function )

A test build of the plugin is availible here:
http://www.mathpudding.com/topsecretsamp/MathPlugin.dll (FIXED: no more dependancies on stdlib)
http://www.mathpudding.com/topsecretsamp/MathPlugin.so (32 bit linux plugin)


Big thanks to Zeex for helping out with the plugin, his new GDK was instrumental in speeding up this plugin.

Grab copy of code from https://github.com/JernejL/samp-mp and compile - code::blocks works ok for windows, you will also need a copy of Zeex's samp GDK: https://github.com/Zeex/sampgdk . Linux makefile is included too.

If you experience script crashes / glitches after compiling this on your own (happens rarely, only with specific scripts), make these changes to sampgdk, the binaries provided above already come with these modifications:

Код:
In wrapper.cpp comment this out:
//sampgdk::InitializeCallbacks();

amxapihooks.cpp - comment this out:
//amxFindPublicHook.Install(amxExportsTable[PLUGIN_AMX_EXPORT_FindPublic], (void*)FindPublic);
//amxExecHook.Install(amxExportsTable[PLUGIN_AMX_EXPORT_Exec], (void*)Exec);
  • Update on 13 august:
    fixed MPGetVehicleOccupantCnt (it only counted drivers)
    added MPGetVehicleSurfersCnt
    added MPProjectPointOnPlayer
  • Update on 25 march 2015:

    native MPFloatIsFinite(Float:in); // returns 1 if floating point is finite (when it is NOT NaN or INF)
    native Float:MPFiniteFloat(Float:in, Float:alternative = 0.0); // returns the same floating point as received, but if the number is not finite (INF / NaN) it will return the second parameter.
    native Float:MPReturnInf(positive); // returns a invalid float - infinite (+inf / -inf)
    native Float:MPReturnNan(positive); // returns a invalid float - NaN (+NaN / -NaN)
Reply


Messages In This Thread
[REL] Math Plugin - by JernejL - 20.07.2011, 18:08
Re: WIP Math Plugin - by Calgon - 20.07.2011, 18:11
Re: WIP Math Plugin - by JernejL - 20.07.2011, 18:15
Re: WIP Math Plugin - by Donya - 20.07.2011, 18:15
Re: WIP Math Plugin - by Calgon - 20.07.2011, 18:17
Respuesta: WIP Math Plugin - by clavador - 20.07.2011, 18:20
Re: Respuesta: WIP Math Plugin - by JernejL - 20.07.2011, 18:21
Re: WIP Math Plugin - by Kyosaur - 20.07.2011, 19:30
Re: WIP Math Plugin - by Omega-300 - 20.07.2011, 19:45
Re: WIP Math Plugin - by Gamer_Z - 20.07.2011, 20:33
Re: WIP Math Plugin - by Jay_ - 20.07.2011, 20:40
Re: WIP Math Plugin - by gamer931215 - 20.07.2011, 22:16
Re: WIP Math Plugin - by JernejL - 20.07.2011, 22:18
Re: WIP Math Plugin - by Mauzen - 20.07.2011, 22:33
Re: WIP Math Plugin - by JernejL - 20.07.2011, 22:52
Re: WIP Math Plugin - by linuxthefish - 20.07.2011, 23:17
Re: WIP Math Plugin - by Famalamalam - 20.07.2011, 23:50
Re: WIP Math Plugin - by JernejL - 20.07.2011, 23:54
Re: WIP Math Plugin - by Whitetiger - 21.07.2011, 00:29
Re: WIP Math Plugin - by linuxthefish - 21.07.2011, 00:38
Re: WIP Math Plugin - by Famalamalam - 21.07.2011, 00:41
Re: WIP Math Plugin - by JernejL - 21.07.2011, 00:54
Re: WIP Math Plugin - by JernejL - 21.07.2011, 11:05
Re: WIP Math Plugin - by Babul - 21.07.2011, 14:01
Re: WIP Math Plugin - by samiras - 21.07.2011, 14:58
Re: WIP Math Plugin - by JernejL - 21.07.2011, 16:42
Re: WIP Math Plugin - by steki. - 21.07.2011, 17:36
Re: WIP Math Plugin - by wups - 21.07.2011, 20:35
Re: WIP Math Plugin - by Incognito - 22.07.2011, 13:20
Re: WIP Math Plugin - by samiras - 24.07.2011, 17:55
Re: [REL] Math Plugin - by dr.pepper - 14.08.2011, 18:11
Re: [REL] Math Plugin - by Blacklite - 16.08.2011, 10:21
Re: [REL] Math Plugin - by cyber_punk - 17.08.2011, 21:27
Re: [REL] Math Plugin - by linuxthefish - 17.08.2011, 21:38
Re: [REL] Math Plugin - by Kar - 17.08.2011, 22:20
Re: [REL] Math Plugin - by Bakr - 19.08.2011, 03:25
Re: [REL] Math Plugin - by JernejL - 20.08.2011, 16:05
Re: [REL] Math Plugin - by Bakr - 21.08.2011, 01:36
Re: [REL] Math Plugin - by BeckzyBoi - 28.08.2011, 03:30
Re: [REL] Math Plugin - by [IL]HeHu - 29.08.2011, 14:17
Re: [REL] Math Plugin - by AndreT - 29.08.2011, 14:32
Re: [REL] Math Plugin - by Kar - 29.08.2011, 14:51
Re: [REL] Math Plugin - by JernejL - 29.08.2011, 18:27
Re: [REL] Math Plugin - by SourceCode - 15.11.2011, 14:17
Re: [REL] Math Plugin - by Niko_boy - 15.11.2011, 15:25
Re: [REL] Math Plugin - by leong124 - 17.11.2011, 08:45
Re: [REL] Math Plugin - by BeckzyBoi - 22.12.2011, 21:56
Re: [REL] Math Plugin - by leong124 - 23.12.2011, 04:07
Re: [REL] Math Plugin - by BeckzyBoi - 23.12.2011, 22:54
Re: [REL] Math Plugin - by leong124 - 24.12.2011, 16:54
Re: [REL] Math Plugin - by TheArcher - 03.01.2012, 23:30
Re: [REL] Math Plugin - by RyDeR` - 04.01.2012, 00:35
Re: [REL] Math Plugin - by DrTHE - 04.01.2012, 00:44
Re: [REL] Math Plugin - by TheArcher - 04.01.2012, 01:05
Re: [REL] Math Plugin - by zgintasz - 09.06.2012, 12:11
Re: [REL] Math Plugin - by cyber_punk - 04.10.2012, 19:55
Re: [REL] Math Plugin - by TheArcher - 01.02.2013, 18:14
Re: [REL] Math Plugin - by TheArcher - 02.02.2013, 10:25
Re: [REL] Math Plugin - by JernejL - 25.03.2015, 12:14

Forum Jump:


Users browsing this thread: 7 Guest(s)