SA-MP Forums Camera Vectors in R5 - how to use, READ THIS!
 New Account Members List Search Today's Posts Mark Forums Read

 24/03/2010, 06:20 PM #1 JernejL Beta Tester     Join Date: Jan 2006 Location: Slovenia Posts: 610 Reputation: 407 Camera Vectors in R5 - how to use, READ THIS! First of all, discard the "UP" vector, the only vector of use currently is the FRONT vector. The FRONT vector is simply a unit length (1 unit) vector direction in which the player is aiming from the camera position. How to make sense of this..: Basically, if you add camera front vector to the camera position vector, you will get another point in game space which is exactly 1 unit apart from the player and is in the direction where the player is looking at. That camera target point can be then moved forward and backwards to have a point of reference against a specific target and see if the player is aiming towards it. Example usage: 1. calculate distance from camera position to target check position (say a specific object) 2. rescale the front vector so it's length will be the distance to object to check, THIS IS VERY EASY - Since the vector is always of 1.0 length you can simply multiply the front vector XYZ values by the distance from #1, we will call this vector a tempcamtarget vector. 3. Now since you have the tempcamtarget point that is of known distance away from the target point and towards what the player is looking at, you can do a simple distance check from the tempcamtarget to the object position, the distance returned will be how far off from target object the player is looking, so you can know if he's looking at a certain object, or looking away from it. EXAMPLE CODE: Code: ```Float:DistanceCameraTargetToLocation(Float:CamX, Float:CamY, Float:CamZ, Float:ObjX, Float:ObjY, Float:ObjZ, Float:FrX, Float:FrY, Float:FrZ) { new Float:TGTDistance; // get distance from camera to target TGTDistance = floatsqroot((CamX - ObjX) * (CamX - ObjX) + (CamY - ObjY) * (CamY - ObjY) + (CamZ - ObjZ) * (CamZ - ObjZ)); new Float:tmpX, Float:tmpY, Float:tmpZ; tmpX = FrX * TGTDistance + CamX; tmpY = FrY * TGTDistance + CamY; tmpZ = FrZ * TGTDistance + CamZ; return floatsqroot((tmpX - ObjX) * (tmpX - ObjX) + (tmpY - ObjY) * (tmpY - ObjY) + (tmpZ - ObjZ) * (tmpZ - ObjZ)); }``` The result of the function is how close to the object centre the player is looking at, use it like - if value is < 1.0 then the player is looking at the object within target diameter of 2.0 units (for 1.0 radius.. diameter is 2.0) Code is untested, but compiles and should work. __________________ samp://198.50.173.59:7777 - Partyserver - TurtleServer (now with extra turtles)! SA-MP map editor: Not a in-game script but a proper windows application! http://forum.sa-mp.com/showthread.php?t=282801
 24/03/2010, 06:42 PM #2 Norn High-roller     Join Date: Jul 2008 Location: Northern Ireland Posts: 2,692 Reputation: 206 Re: Camera Vectors in R5 - how to use, READ THIS! From this can we calculate a vehicle in front of the players distance/players distance simply by looking at it? __________________ Pursuing other endeavours. Skype: datinvictusguy
24/03/2010, 06:44 PM   #3
JernejL
Beta Tester

Join Date: Jan 2006
Location: Slovenia
Posts: 610
Reputation: 407
Re: Camera Vectors in R5 - how to use, READ THIS!

Quote:
 Originally Posted by Norn [BINMAN ] From this can we calculate a vehicle in front of the players distance/players distance simply by looking at it?
Yes, the script can know exact what car you are looking at.
__________________

samp://198.50.173.59:7777 - Partyserver - TurtleServer (now with extra turtles)!

SA-MP map editor: Not a in-game script but a proper windows application!

 24/03/2010, 06:47 PM #4 wafffllesss Huge Clucker   Join Date: Apr 2007 Posts: 413 Reputation: 1 Re: Camera Vectors in R5 - how to use, READ THIS! Will be waiting for your example code. ( More upgrades to my zombie script =D )
24/03/2010, 07:23 PM   #5
Norn
High-roller

Join Date: Jul 2008
Location: Northern Ireland
Posts: 2,692
Reputation: 206
Re: Camera Vectors in R5 - how to use, READ THIS!

Quote:
Originally Posted by RedShirt (JernejL)
Quote:
 Originally Posted by Norn [BINMAN ] From this can we calculate a vehicle in front of the players distance/players distance simply by looking at it?
Yes, the script can know exact what car you are looking at.
Epic thanks for explaining this in simple terms.
__________________
Pursuing other endeavours.

Skype: datinvictusguy

 24/03/2010, 09:13 PM #6 JernejL Beta Tester     Join Date: Jan 2006 Location: Slovenia Posts: 610 Reputation: 407 Re: Camera Vectors in R5 - how to use, READ THIS! CODE EDITED - THIS IS CORRECT AND TESTED! Code: ```Float:DistanceCameraTargetToLocation(Float:CamX, Float:CamY, Float:CamZ, Float:ObjX, Float:ObjY, Float:ObjZ, Float:FrX, Float:FrY, Float:FrZ) { new Float:TGTDistance; // get distance from camera to target TGTDistance = floatsqroot((CamX - ObjX) * (CamX - ObjX) + (CamY - ObjY) * (CamY - ObjY) + (CamZ - ObjZ) * (CamZ - ObjZ)); new Float:tmpX, Float:tmpY, Float:tmpZ; tmpX = FrX * TGTDistance + CamX; tmpY = FrY * TGTDistance + CamY; tmpZ = FrZ * TGTDistance + CamZ; return floatsqroot((tmpX - ObjX) * (tmpX - ObjX) + (tmpY - ObjY) * (tmpY - ObjY) + (tmpZ - ObjZ) * (tmpZ - ObjZ)); }``` Code: ```// EXAMPLE USAGE: checkforcamera(PlayerID) { new Float:CameraPos[3]; new Float:CameraFront[3]; new Float:CheckObjectPos[3] = {-2661.2764,915.7676,79.6685}; // trash can near partyserver torenos GetPlayerCameraPos(PlayerID, CameraPos[0], CameraPos[1], CameraPos[2]); GetPlayerCameraFrontVector(PlayerID, CameraFront[0], CameraFront[1], CameraFront[2]); new Float:distc; distc = DistanceCameraTargetToLocation(CameraPos[0], CameraPos[1], CameraPos[2], CheckObjectPos[0], CheckObjectPos[1], CheckObjectPos[2], CameraFront[0], CameraFront[1], CameraFront[2]); new string[128]; if (distc < 2.0) { format(string,sizeof(string),"YOU SEE IT."); SendClientMessage(PlayerID, COLOR_RED, string); } return true; }``` __________________ samp://198.50.173.59:7777 - Partyserver - TurtleServer (now with extra turtles)! SA-MP map editor: Not a in-game script but a proper windows application! http://forum.sa-mp.com/showthread.php?t=282801
 25/03/2010, 05:15 AM #7 CracK Huge Clucker     Join Date: Nov 2007 Posts: 422 Reputation: 2 Re: Camera Vectors in R5 - how to use, READ THIS! Code: ```stock IsPlayerAimingAt(playerid, Float:x, Float:y, Float:z, Float:radius) { new Float:cx,Float:cy,Float:cz,Float:fx,Float:fy,Float:fz; GetPlayerCameraPos(playerid, cx, cy, cz); GetPlayerCameraFrontVector(playerid, fx, fy, fz); return (radius >= DistanceCameraTargetToLocation(cx, cy, cz, x, y, z, fx, fy, fz)); }``` returns 1, if a player is looking at position x,y,z Use radius 1.0 for players __________________ • Custom Enex loader 1.0 • map2pwn
 25/03/2010, 07:08 AM #8 Burridge High-roller     Join Date: Nov 2008 Location: England Posts: 2,108 Reputation: 33 Re: Camera Vectors in R5 - how to use, READ THIS! Thanks, RedShirt. Good post. __________________ Please do not PM me for scripting help, use the Scripting Help section of the forums. My Youtube Channel
 25/03/2010, 07:18 PM #9 boelie Gangsta     Join Date: Apr 2009 Location: San Fierro Posts: 661 Reputation: 1 Re: Camera Vectors in R5 - how to use, READ THIS! Hmm this might sound noobish but im trying IsPlayerAimingAt in a command but im not sure if im doing it correct. Can someone give an example ? __________________
25/03/2010, 07:30 PM   #10
JernejL
Beta Tester

Join Date: Jan 2006
Location: Slovenia
Posts: 610
Reputation: 407
Re: Camera Vectors in R5 - how to use, READ THIS!

Quote:
 Originally Posted by boelie Hmm this might sound noobish but im trying IsPlayerAimingAt in a command but im not sure if im doing it correct. Can someone give an example ?
Just call it with playerid, target coords and target radius, how hard is that?
__________________

samp://198.50.173.59:7777 - Partyserver - TurtleServer (now with extra turtles)!

SA-MP map editor: Not a in-game script but a proper windows application!

 Thread Tools Display Modes Linear Mode

 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 Forum Rules

 Similar Threads Thread Thread Starter Forum Replies Last Post potato Help Archive 1 08/08/2010 05:09 AM TKZ227 Help Archive 1 04/06/2010 11:24 PM Kar Help Archive 8 03/06/2010 08:12 AM CharlieScene Help Archive 3 13/04/2010 05:46 PM DeltaAirlines12 Help Archive 8 15/08/2009 10:41 PM

All times are GMT. The time now is 04:39 PM.

 -- (EN) English -- (ES) Español -- (RU) Русски Contact Us - SA-MP - Archive - Top