[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
#2

Could you create some functions for the vehicle quarternion maths, simplifying it for those who really don't have a clue with maths?

Also, nice work - it sounds like it could be very useful considering that there will be a million suggestions incoming from other people who could do with some extra helpful math functions.
Reply
#3

Quote:
Originally Posted by Calg00ne
Посмотреть сообщение
Could you create some functions for the vehicle quarternion maths, simplifying it for those who really don't have a clue with maths?
I already did that - look at MPProjectPointOnVehicle and MPGetVehicleUpsideDown because you didn't look or you are blind..

MPProjectPointOnVehicle can be used to project point on a car at any angle - imagine dropping barrels from trunk or making directional boost.. MPGetVehicleUpsideDown can be used for detecting how upside-down the car is (from 1 totally upwards to 0.0 when on side and -1 as totally flipped over.)
Reply
#4

Suggestion
pawn Код:
CalculatePointsBetweenPAAndPB(points, Float:PointA[3], Float:PointB[3], Float:Point_return_array);
Quote:
Originally Posted by JernejL
Посмотреть сообщение
MPProjectPointOnVehicle can be used to project point on a car at any angle - imagine dropping barrels from trunk
I hope later on when it's finished you can make an example of dropping barrels, because that's exactly what I've been looking for for like 2-3 months now
Reply
#5

Quote:

simplifying it for those who really don't have a clue with maths
As I implied, I don't really have a clue with maths, so it's a bit hard to tell when you don't comment the functions or make it obvious from within the function names.
Reply
#6

The aiming is obstructed by buildings? :O
Reply
#7

Quote:
Originally Posted by clavador
Посмотреть сообщение
The aiming is obstructed by buildings? :O
It's not - unfortunately.
Reply
#8

Nice plugin man, i'll have to take a look at the code later . I definitely see this helping a lot of people.


Edit oh no download link... guess i'll have to get on IRC :P.
Reply
#9

It should be like general rule to place code in some Revision Control System either your own or public one like ******code or github or similar because otherwise it is hard to make contributions to it.
Reply
#10

what is the irc address port?
Reply
#11

An efficient version of GetDistanceToPoint would be nice, since floatsqroot in PAWN is _slow_
Reply
#12

Looks nice, most of the functions existed already though on the sa-mp forums. Is this really a lot faster as in pawn ?

Anyway i dont need it at the moment, but if start working on some gamemode in the future i will probally use this !
Reply
#13

Quote:
Originally Posted by Jay_
Посмотреть сообщение
An efficient version of GetDistanceToPoint would be nice, since floatsqroot in PAWN is _slow_
Ok, i added a few more based on your ideas:

MPInterpolatePoint - as suggested by Donya
MPDistance - a bit faster distance check
MPClamp360 - in-wraps angle number to a value to 0..360 range, (preserving direction, uses the wanted range)

MPFSQRT - wrapper for 0x5f3759df fsqrt
MPFDistance - even faster distance check (uses fastsqrt - ****** for 0x5f3759df )
MPFNormalize - 0x5f3759df fsqrt powered version of vector normalization


Any other good ideas?
Reply
#14

Nice idea, this will become handy when optimizing scripts (unfortuantely not many people do that )

Edit: ignore my suggestion, just realized it is already implemented.
Reply
#15

Quote:
Originally Posted by ******
Посмотреть сообщение
There's MPCrossProduct, why not MPDotProduct? Also intersection functions would be useful, for example checking if a line and a circle/sphere/cylinder interact.
Cause noone asked for it yet, added it now.

There is already line/circle function, it's called MPDistancePointLine - circle / radius is just part of distance equation there.

As for extra formulas - cylinder etc.. checks, the plugin will be GPL'd on release, so you will be able to contribute to it.
Reply
#16

What dose this actually do, and why would it be useful?

Quote:
Originally Posted by Calg00ne
Посмотреть сообщение
As I implied, I don't really have a clue with maths, so it's a bit hard to tell when you don't comment the functions or make it obvious from within the function names.
Lies.
Reply
#17

JernejL, I think you are a hero if you can accomplish this.
Reply
#18

Quote:
Originally Posted by linuxthefish
Посмотреть сообщение
What dose this actually do, and why would it be useful?
WOULD YOU PLEASE READ THE FIRST POST NEXT TIME BEFORE POSTING? IT WILL MAKE YOU LOOK LESS IGNORANT. THANK YOU.

Famalamalam: plugin is already working, if you want to test it before release just let me know.
Reply
#19

Quote:

native MPGetAimTarget(PlayerID); // returns player that this player is aiming at or invalid player id if no player in target area.

Is this more accurate than the other ways of detecting who is being aimed at? Can this be used as a viable option to detect damage each player has dealt to other players?
Reply
#20

Quote:
Originally Posted by JernejL
Посмотреть сообщение
WOULD YOU PLEASE READ THE FIRST POST NEXT TIME BEFORE POSTING? IT WILL MAKE YOU LOOK LESS IGNORANT. THANK YOU.
I have no capslock, or i would be shouting. I understand the game helpers, but how is the maths bit useful? Any examples?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)