camera troubles

Started by
2 comments, last by mr2071 22 years, 1 month ago
I created a heightmap and wish to move my camera through the heightmap making it so I can only see the top of the map. I''m using digiben''s camera class and I modified the "move" method to this:
  
void Camera::move(float direction)
{
	Vector3 vVector={0};						// Init a vVector for our view

	Land land;

	int nHeight = land.Height((int) m_vPosition.x,(int) m_vPosition.z);

	// Get our view vVector (The direciton we are facing)

	vVector.x = m_vView.x - m_vPosition.x;		// This gets the direction of the X	

	vVector.y = m_vView.y - m_vPosition.y;		// This gets the direction of the Y

	vVector.z = m_vView.z - m_vPosition.z;		// This gets the direction of the Z


	m_vPosition.x += vVector.x * direction;		// Add our acceleration to our position''s X

	m_vPosition.y = (float)nHeight;
	m_vPosition.z += vVector.z * direction;		// Add our acceleration to our position''s Z


	m_vView.x += vVector.x * direction;			// Add our acceleration to our view''s X

	m_vView.y = (float)nHeight;
	m_vView.z += vVector.z * direction;			// Add our acceleration to our view''s Z



}
  
if you notice, the height and position of the camera are set to the height at that spot in the height map. What''s happening is that as I walk through my map, I end up going through the mountains although it still raises the height of the camera. Its just not enough. Since there is no rotating around a point, it should not be that difficult to not see through the bottom of the map. I''m very new to this and was wondering if someone could help me find a solution that would make the camera not look through the map. At most, it should walk up the hills and face straight into mountain sides. Thanks for any help!
Advertisement
Set the camera a little bit higher then the terrain :

m_vPosition.y = (float) nHeight + 2.0f; //look for a value that
// looks best
m_vView.y = (float) nHeight + 2.0f;
"THE INFORMATION CONTAINED IN THIS REPORT IS CLASSIFIED; DO NOT GO TO FOX NEWS TO READ OR OBTAIN A COPY." , the pentagon
Thank you, that seems to help although going up steeper slopes still causes me to go through the map and I would alsolike to be closer to the ground at the lower levels of the map.

I''d also like to be able to stick an object in front of the camera at all times. I''m trying this right now by doing this:


  void Land::RenderBall(){		glTranslatef(c.m_vPosition.x+5.0f, c.m_vPosition.y, c.m_vPosition.z+5.0f);	glColor4f(0.7f, 0.7f, 1.0f, 0.7f);	glutSolidSphere(5.0, 20, 18);}  


Problem here is that the ball NEVER moves. I call renderheightmap just before it and if I call glLoadIdentity() inbetween rendering heightmap and renderball methods, i can''t seem to find the ball anywhere.

I thought that glLoadIdentity() would just make it go back to the point of origin and then the call to translate it to the current position of the camera would put it there.

The other way I do it is to call glPushMatrix() before the rendermap method, then call rendermap, then call renderball, then call glPopMatrix()

Thanks for helping
Oops. Well I figured out the ball problem. I just had the wrong instance of the camera class being used to get the ball positions.

That part works now

This topic is closed to new replies.

Advertisement