21.07.2011, 00:41
[Plugin] [REL] Math Plugin
21.07.2011, 00:54
It might work for that if ran fast.. say in onplayerupdate callback, but it would run on server simulation and it might not be what happens on the client in every case. I don't think that function is also very optimized to run in each player update - but we'll have to test once plugin is released.
21.07.2011, 11:05
21.07.2011, 14:01
i would love some functions which care for Euler Angles / Quaternions. iam scripting on my object editor for ages yet, and i failed 3 times at including the GetVehicleRotationQuat for calculating some rotations.
there are so many sources on how to code matrices for converting/manipulating rotation quats, but the effort would freeze the server, and its a bit too hard to imagine 4 dimensional things >-<
anyways, by providing a rotation in that quat format makes it possible to interpolate between 2 totally different facing angles by using ONE quaternion-set...
why do i tell/ask/spam that?
imagine a race track editor, using all new street objects, which fit exactly together...
now imagine a 40 meter long road. then a ramp up, then a slight turn to the left.... aw screw it. brb, taking some vids now...
and here it is:
anyways, prepare for a challenge in maths if you dare to ^^
****** Quaternions/euler angles, this will link you to pure brain madness!
thank you for taking time to read through all this...
edit: oops. the axis got swapped. the "less important" axis is indeed the Z axis. i can rotate an even screwed map on the Z axis. that one which points up the sky
its a total mess to think about all that..
there are so many sources on how to code matrices for converting/manipulating rotation quats, but the effort would freeze the server, and its a bit too hard to imagine 4 dimensional things >-<
anyways, by providing a rotation in that quat format makes it possible to interpolate between 2 totally different facing angles by using ONE quaternion-set...
why do i tell/ask/spam that?
imagine a race track editor, using all new street objects, which fit exactly together...
now imagine a 40 meter long road. then a ramp up, then a slight turn to the left.... aw screw it. brb, taking some vids now...
and here it is:
anyways, prepare for a challenge in maths if you dare to ^^
****** Quaternions/euler angles, this will link you to pure brain madness!
thank you for taking time to read through all this...
edit: oops. the axis got swapped. the "less important" axis is indeed the Z axis. i can rotate an even screwed map on the Z axis. that one which points up the sky
its a total mess to think about all that..
21.07.2011, 14:58
(
Последний раз редактировалось samiras; 24.07.2011 в 18:17.
Причина: Edited one mispelled word.
)
Quote:
I'm sure everyone will appreciate the benefits of running this in native C code for greater speed.
|
You could simply do all of those as a 'Include' which is more useful for this purposes.
Maybe take a look more deeper what are plugins used for.
21.07.2011, 16:42
Quote:
WHAT? I think YOU need to look at what plugins are for and understand the difference between C++ and PAWN (and, more importantly, which is faster).
|
pawn versions
Код:
stock GetVehicleDriver(vehicleid) { for (new i; i<500; i++) { if (!IsPlayerConnected(i)) continue; if (GetPlayerState(i) != PLAYER_STATE_DRIVER) continue; if (GetPlayerVehicleID(i) == vehicleid) { return i; } } return -1; }
Код:
int GetVehicleDriver(int vehicleid) { if ((vehicleid == 0) || (vehicleid == INVALID_VEHICLE_ID) || (vehicleid > MAX_VEHICLES)) return INVALID_PLAYER_ID; int i; for (i = 0; i < max_players; i++) { if (invoke->callNative(&PAWN::IsPlayerConnected, i) == false) // no connected player in slot? continue; if (invoke->callNative(&PAWN::GetPlayerState, i) != PLAYER_STATE_DRIVER) continue; // not a driver of any vehicle? int thisplayervehid; thisplayervehid = invoke->callNative(&PAWN::GetPlayerVehicleID, i); // todo: maybe use IsPlayerInVehicle instead. if (thisplayervehid == vehicleid) // found a connected driver in this car. return i; } return INVALID_PLAYER_ID; // found no driver. }
Код:
#define MAXTEST 500 new test1; test1 = GetTickCount(); for(new a; a < 500; ++a) { MPGetVehicleDriver(1); //returnit(a); } printf("# MPGetVehicleDriver %d", GetTickCount() - test1); new test2; test2 = GetTickCount(); for(new a; a < 500; ++a) { GetVehicleDriver(1); } printf("# GetVehicleDriver %d", GetTickCount() - test2);
****** and other experts - any idea why the c++ version is slower? i managed to track down to invoke->callNative function.. so whenever i call sa-mp natives via invoke that's significantly slower than doing it in pawn (pure math functions work faster tho), so this is unacceptable to me.. if calling samp natives via invoke makes the whole thing slower than in pawn, i should just stop this project - there is no other option.
Also, full source: http://code.******.com/p/samp-mp/sou...e/#svn%2Ftrunk
21.07.2011, 17:36
I think High Level languages tends to be slower than lowers.
Great plugin.
Great plugin.
21.07.2011, 20:35
You can try implenting MapAndreas into Aim functions. That way you could aim to a person through a building.
22.07.2011, 13:20
(
Последний раз редактировалось Incognito; 29.07.2011 в 07:11.
)
Quote:
****** and other experts - any idea why the c++ version is slower? i managed to track down to invoke->callNative function.. so whenever i call sa-mp natives via invoke that's significantly slower than doing it in pawn (pure math functions work faster tho), so this is unacceptable to me.. if calling samp natives via invoke makes the whole thing slower than in pawn, i should just stop this project - there is no other option.
|
Anyway, I've done some profiling and Zeex's gamemode SDK is clearly the winner here.
Код:
void methodOne() { boost::chrono::high_resolution_clock::time_point begin = boost::chrono::high_resolution_clock::now(); for (int i = 0; i < 1000000; ++i) { invoke->callNative(&PAWN::GetPlayerPos, playerid, &x, &y, &z); } boost::chrono::duration<double, boost::milli> end = boost::chrono::high_resolution_clock::now() - begin; logprintf("methodOne(): %g", end.count()); }
Код:
void methodTwo() { boost::chrono::high_resolution_clock::time_point begin = boost::chrono::high_resolution_clock::now(); for (int i = 0; i < 1000000; ++i) { samp::GetPlayerPos(playerid, x, y, z); } boost::chrono::duration<double, boost::milli> end = boost::chrono::high_resolution_clock::now() - begin; logprintf("methodTwo(): %g", end.count()); }
Код:
[07:20:48] methodOne(): 305.934 [07:20:48] methodTwo(): 22.3173
Edit: I also don't mean to say that callNative is incredibly slow. In the test above, each call took about 300 nanoseconds (or 300 billionths of a second) to complete. That's still pretty fast, even if a PAWN implementation is a bit faster.
24.07.2011, 17:55
Quote:
WHAT? I think YOU need to look at what plugins are for and understand the difference between C++ and PAWN (and, more importantly, which is faster).
|
Quote:
so whenever i call sa-mp natives via invoke that's significantly slower than doing it in pawn (pure math functions work faster tho), so this is unacceptable to me.. if calling samp natives via invoke makes the whole thing slower than in pawn, i should just stop this project - there is no other option.
|
Thanks
14.08.2011, 18:11
Matttth Plugin, I will download this and keep it. Let the Magnet Turtles be with this Plugin!
16.08.2011, 10:21
Been waiting for this for 2+ years
17.08.2011, 21:27
Anyone else having the paths break when converting the project over to vc++ 2010?
17.08.2011, 21:38
Is it safe to use the compiled Linux version?
17.08.2011, 22:20
19.08.2011, 03:25
Unfortunately, I'm not the greatest with math and can hardly understand how to properly use half of these functions. I was curious, as you PMed me awhile ago telling me you had a function that could do so, if one of these functions could be manipulated to allow correct vehicle offsets when placing objects on certain areas of the map like slopes. For example, if I wanted to place a trash bin on the side of a trash truck, while it's going uphill, using the default offsets wouldn't work.
Would you mind showing me a short example of how to make that work with one of these functions (of course if it's not already added that would be a possible suggestion)?
Thanks.
Would you mind showing me a short example of how to make that work with one of these functions (of course if it's not already added that would be a possible suggestion)?
Thanks.
20.08.2011, 16:05
Quote:
Unfortunately, I'm not the greatest with math and can hardly understand how to properly use half of these functions. I was curious, as you PMed me awhile ago telling me you had a function that could do so, if one of these functions could be manipulated to allow correct vehicle offsets when placing objects on certain areas of the map like slopes. For example, if I wanted to place a trash bin on the side of a trash truck, while it's going uphill, using the default offsets wouldn't work.
Would you mind showing me a short example of how to make that work with one of these functions (of course if it's not already added that would be a possible suggestion)? Thanks. |
pawn Код:
public OnPlayerKeyStateChange(PlayerID, NewKeys, OldKeys) {
// pressing fire key
if ((NewKeys & KEY_FIRE) && !(OldKeys & KEY_FIRE)) {
if (IsPlayerInAnyVehicle(PlayerID)) {
new vehtype;
vehtype = GetVehicleModel(GetPlayerVehicleID(PlayerID));
if (vehtype == 564) {// while in RC tiger
new time;
time = GetPVarInt(PlayerID, "LastTigerShot");
if (time + 500 < TickCount()) {
new Float:turretstart[3];
new Float:inp[3];
inp[0] = 0.000; inp[1] = -1.2559; inp[2] = 0.3384;
MPProjectPointOnVehicle(GetPlayerVehicleID(PlayerID), inp[0], inp[1], inp[2], turretstart[0], turretstart[1], turretstart[2], 1);
CreateObject( 921, turretstart[0], turretstart[1], turretstart[2], 0.0, 0.0, 0.0);
SetPVarInt(PlayerID, "LastTigerShot", TickCount()); // shot time
}
}
}
}
}
When you hit fire key while inside a RC tiger, this will take the turret end point coordinates, and project them thru car's rotations to get exit coordinates in game world space, then create a small light object at those points.
An alternative would be, to extend the exit turret coordinates further, and create a explosion instead, this would make the RC tank able to fire / explode things properly.
Screenshot - notice that objects are placed correctly taking the rc tank's pitch / roll / yaw into account:
You can use this, and get trash van's specific coordinates to place trash cans behind it, it's easy to get coordinates on vehicles - place a car in my map editor at exact 0,0,0 coordinates with no rotation, then click on the vehicle and status bar will show you vehicle-based coordinates.
21.08.2011, 01:36
Great! Thank you very much for the example, I got one of my desired projects working as I intended. Amazing how I spent hours upon hours trying to get the correct code to manipulate the coordinates like so (not including the time doing research), and it can all be done with a simple function now.
Very nice work on this plugin and your Map Editor.
Very nice work on this plugin and your Map Editor.
28.08.2011, 03:30
Some questions:
1) Could you please make a MPDistance2D?
2) Is MPDistance faster than PointToPoint3D in the PointToPoint plugin?
3) How is MPFDistance less accurate? :S Can you please give me examples of what MPDistance and MPFDistance will return using the same coordinates?
4) Does MPGetTrailerTowingVehicle loop through all vehicles to find the towing vehicle or do you keep track of trailers using OnPlayerUpdate and OnUnoccupiedVehicleUpdate?
Thanks
1) Could you please make a MPDistance2D?
2) Is MPDistance faster than PointToPoint3D in the PointToPoint plugin?
3) How is MPFDistance less accurate? :S Can you please give me examples of what MPDistance and MPFDistance will return using the same coordinates?
4) Does MPGetTrailerTowingVehicle loop through all vehicles to find the towing vehicle or do you keep track of trailers using OnPlayerUpdate and OnUnoccupiedVehicleUpdate?
Thanks
29.08.2011, 14:17
I am sorry for my stupidity, but where do I get the .inc file?
« Next Oldest | Next Newest »
Users browsing this thread: 3 Guest(s)