Advertisement

Free flying tutorial

Started by April 21, 2003 02:07 PM
0 comments, last by Ickno 21 years, 10 months ago
I''ve been looking at the radar class in this game tutorial, and I just dunnot understand one part of this code.
  
bool RADAR::GetRadarCoord(ACTOR *actor, VECTOR3D pos3D, VECTOR2D *radarPos2D)
	{
	float radarR, radarCOS, radarSIN, rT;
	VECTOR3D deltaPos, v;

	//Compute coords of object relative to the actor

	deltaPos = pos3D-actor->worldPos;
	
	//Normalize that

	deltaPos.Normalize();
	
	//Distance of blip from center of radar is cosine of angle

	//between view direction and direction to object

	radarR = actor->directionVector.DotProduct(deltaPos);
	
	//Determine projection of object on plane perpendicular

	//to viewing plane

	v = deltaPos+actor->directionVector*(-radarR);
	
	//Handle special case of null v, meaning object is on

	//line of sight

	if(v.IsNull())
	{
		(*radarPos2D) = center;
		return true;
	}
	
	//Else normalize v

	v.Normalize();
	
	//v is now a vector from the actor''s viewpoint to projection

	//of object on the actors''s plane. Compute angle from actors''s

	//up vector to object

	radarSIN = actor->rightVector.DotProduct(v);
	radarCOS = actor->upVector.DotProduct(v);
	
	//Convert to cartesian

	rT = (1.0f-radarR)/2.0f;
	(*radarPos2D).x = center.x+radius*(-rT)*radarSIN;
	(*radarPos2D).y = center.y+radius*rT*radarCOS;
	
	return true;
	}
  
Could someone please explain the code after the "//convert to cartesian" comment. What is rT = 1.0f-radarR/2.0f for? radarR is the dot product of the look at vector and a vector from the players position to the enemys position.. I understand that this code is to get the 2d cords on the radar, but still don''t follow those last 3 lines.. Thanks a bunch.
take a few 3D points and a calulator(maybe even a graphing one) plug it in, and watch what happens, you might get some messy numbers, but at least you will understand what happens and be able to follow it. It works for me.

Out - The Prox
-------------------
Remember: No shortcuts...
They may be faster, but someday you will be penalized.
NARF - Pinky and the Brain

This topic is closed to new replies.

Advertisement