SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Plugin Development

Reply
 
Thread Tools Display Modes
Old 20/07/2011, 06:08 PM   #1
JernejL
Beta Tester
 
JernejL's Avatar
 
Join Date: Jan 2006
Location: Slovenia
Posts: 580
Reputation: 418
Flowers [REL] Math Plugin

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 Code:
// 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); // [url]http://paulbourke.net/geometry/pointline/[/url] 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:

Code:
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)
__________________
Please, do no message me anymore, i'm no longer part of sa-mp scene.

I will not reply to private messages.

Last edited by JernejL; 25/03/2015 at 12:12 PM.
JernejL is offline   Reply With Quote
Old 20/07/2011, 06:11 PM   #2
Calgon
Banned
 
Join Date: Jan 2009
Posts: 6,130
Reputation: 1127
Default Re: WIP Math Plugin

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.
Calgon is offline   Reply With Quote
Old 20/07/2011, 06:15 PM   #3
JernejL
Beta Tester
 
JernejL's Avatar
 
Join Date: Jan 2006
Location: Slovenia
Posts: 580
Reputation: 418
Default Re: WIP Math Plugin

Quote:
Originally Posted by Calg00ne View Post
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.)
__________________
Please, do no message me anymore, i'm no longer part of sa-mp scene.

I will not reply to private messages.
JernejL is offline   Reply With Quote
Old 20/07/2011, 06:15 PM   #4
Donya
Gangsta
 
Join Date: Mar 2011
Posts: 715
Reputation: 33
Default Re: WIP Math Plugin

Suggestion
pawn Code:
CalculatePointsBetweenPAAndPB(points, Float:PointA[3], Float:PointB[3], Float:Point_return_array);

Quote:
Originally Posted by JernejL View Post
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
__________________
[FilterScript]Exception 0xC0000005 at 0x7F120E Protection | OnVehicleMod monitoring. Now Full Protection!

I'm sorry for what was posted earlier, I was hacked.

Last edited by Donya; 20/07/2011 at 07:04 PM.
Donya is offline   Reply With Quote
Old 20/07/2011, 06:17 PM   #5
Calgon
Banned
 
Join Date: Jan 2009
Posts: 6,130
Reputation: 1127
Default Re: WIP Math Plugin

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.
Calgon is offline   Reply With Quote
Old 20/07/2011, 06:20 PM   #6
clavador
Huge Clucker
 
clavador's Avatar
 
Join Date: Jun 2007
Location: Argentina
Posts: 220
Reputation: 71
Default Respuesta: WIP Math Plugin

The aiming is obstructed by buildings? :O
clavador is offline   Reply With Quote
Old 20/07/2011, 06:21 PM   #7
JernejL
Beta Tester
 
JernejL's Avatar
 
Join Date: Jan 2006
Location: Slovenia
Posts: 580
Reputation: 418
Default Re: Respuesta: WIP Math Plugin

Quote:
Originally Posted by clavador View Post
The aiming is obstructed by buildings? :O
It's not - unfortunately.
__________________
Please, do no message me anymore, i'm no longer part of sa-mp scene.

I will not reply to private messages.
JernejL is offline   Reply With Quote
Old 20/07/2011, 07:30 PM   #8
Kyosaur
Gangsta
 
Kyosaur's Avatar
 
Join Date: Mar 2008
Location: USA - California
Posts: 973
Reputation: 349
Default Re: WIP Math Plugin

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.
Kyosaur is online now   Reply With Quote
Old 20/07/2011, 07:45 PM   #9
Omega-300
Banned
 
Join Date: May 2011
Location: In Tha Hood
Posts: 20
Reputation: 0
Default Re: WIP Math Plugin

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.
Omega-300 is offline   Reply With Quote
Old 20/07/2011, 08:33 PM   #10
Gamer_Z
Guest
 
Posts: n/a
Default Re: WIP Math Plugin

what is the irc address port?
  Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Math. Bessensap Help Archive 17 25/10/2010 09:17 PM
Math issue Donny_k Everything and Nothing 3 01/03/2010 07:43 AM
help cordinate math... Battleskull Help Archive 0 12/10/2009 04:52 AM
Simple Math Help StrickenKid Help Archive 6 27/03/2009 10:31 AM


All times are GMT. The time now is 08:18 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.