Camera Vectors in R5 - how to use, READ THIS!
#1

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:

Код:
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.
Reply


Messages In This Thread
Camera Vectors in R5 - how to use, READ THIS! - by JernejL - 24.03.2010, 18:20
Re: Camera Vectors in R5 - how to use, READ THIS! - by Norn - 24.03.2010, 18:42
Re: Camera Vectors in R5 - how to use, READ THIS! - by JernejL - 24.03.2010, 18:44
Re: Camera Vectors in R5 - how to use, READ THIS! - by wafffllesss - 24.03.2010, 18:47
Re: Camera Vectors in R5 - how to use, READ THIS! - by Norn - 24.03.2010, 19:23
Re: Camera Vectors in R5 - how to use, READ THIS! - by JernejL - 24.03.2010, 21:13
Re: Camera Vectors in R5 - how to use, READ THIS! - by CracK - 25.03.2010, 05:15
Re: Camera Vectors in R5 - how to use, READ THIS! - by Burridge - 25.03.2010, 07:08
Re: Camera Vectors in R5 - how to use, READ THIS! - by boelie - 25.03.2010, 19:18
Re: Camera Vectors in R5 - how to use, READ THIS! - by JernejL - 25.03.2010, 19:30
Re: Camera Vectors in R5 - how to use, READ THIS! - by boelie - 25.03.2010, 19:37
Re: Camera Vectors in R5 - how to use, READ THIS! - by MaykoX - 25.03.2010, 19:59
Re: Camera Vectors in R5 - how to use, READ THIS! - by Rac3r - 26.03.2010, 07:22
Re: Camera Vectors in R5 - how to use, READ THIS! - by CracK - 26.03.2010, 11:22
Re: Camera Vectors in R5 - how to use, READ THIS! - by ev0lution - 27.03.2010, 01:36
Re: Camera Vectors in R5 - how to use, READ THIS! - by Norn - 27.03.2010, 08:11
Re: Camera Vectors in R5 - how to use, READ THIS! - by ev0lution - 28.03.2010, 08:35
Re: Camera Vectors in R5 - how to use, READ THIS! - by ev0lution - 02.04.2010, 00:15
Re: Camera Vectors in R5 - how to use, READ THIS! - by SourceCode - 20.09.2011, 01:34
Re: Camera Vectors in R5 - how to use, READ THIS! - by JernejL - 28.09.2011, 21:05
Re: Camera Vectors in R5 - how to use, READ THIS! - by SourceCode - 15.11.2011, 13:45
Re: Camera Vectors in R5 - how to use, READ THIS! - by Banditukas - 02.11.2014, 12:00

Forum Jump:


Users browsing this thread: 3 Guest(s)