Jump to content
  • Advertisement
Sign in to follow this  
jake_Ghost

Disapearing problem when rotating

This topic is 4808 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

The problem occurs when I'm drawing my enemies and rotating them to look where they are going. They disapear when my GetXZRot returns -1.#IND. Here's my drawing code...
void cEnemy :: DrawEnemy()
{
	CVector3 enPos;
	CVector3 enView;
	float angle = 0;

	for (int i = 0; i < EnemyCount; i++)
	{
		enPos = enemy.Cam.Position();
		enView = enemy.Cam.View();

		for (int ter = 0; ter < cTer.TerrainCount; ter++)
		{
			if (enPos.x > cTer.terrain[ter].x &&
				enPos.x < cTer.terrain[ter].x + 1024 &&
				enPos.z > cTer.terrain[ter].y &&
				enPos.z < cTer.terrain[ter].y + 1024)
			{	
				enemy.Cam.PositionCamera(enPos.x,(float)cTer.Height( (int)enPos.x, (int)enPos.z , ter), enPos.z, enView.x, enView.y,enView.z,0,1,0);
				break;
			}
		}

		enPos = enemy.Cam.Position();
		enView = enemy.Cam.View();

		if (GetRange(cCam.Position(), enemy.Cam.Position()) < 4100)
		{
			enemy.Cam.MoveCamera(50.0f);
			angle = GetXZRot(enPos.x, enPos.z,enemy.Cam.m_vPosition.x,enemy.Cam.m_vPosition.z);
			enemy.Cam.MoveCamera(-50.0f);

			angle += 180;

			glPushMatrix();
				glTranslatef(enPos.x, enPos.y, enPos.z);
				
				if (enemy.State != ENEMY_DEAD)
				{
					glRotatef(angle,0.0f,1.0f,0.0f);
				}

				if (enemy.State == ENEMY_DEAD)
				{
					glRotatef(90.0f,enView.x / 100.0f, enView.y / 100.0f, enView.z / 100.0f);
				}

				glEnable(GL_LIGHTING);
				cmod.Render(enemy.Model);
				glDisable(GL_LIGHTING);

			glPopMatrix();
		}
	}
}

Heres the GetXZRot function
float GetXZRot (float posX, float posZ, float viewX, float viewZ)
{
	float Angle = acos((viewX - posX) / cenemy.GetRange(cCam.Position(),cCam.View()) ) * (360 / (2 * pi));
	
	if (posZ > viewZ)
	{
		Angle += 90;
	}
	else if (posX > viewX && posZ < viewZ)
	{
		Angle = 90 - Angle;
	}
	else if (posX > viewX)
	{
		Angle = 360 - Angle;
	}
	else if (posX < viewX || posZ < viewZ)
	{
		Angle = 360 - Angle;
		Angle += 90;
	}

	return Angle;
}

Any know why that function returns that number or how to fix it? Jake

Share this post


Link to post
Share on other sites
Advertisement
cmod.Render(enemy.Model);
This function is probably the one that would be most interesting to have a look at. :)

I'm not sure wether your question is how to return the angle which your enemy faces or how to avoid having it disappear when it faces away from you. If it's the latter, check wether you've enabled backface culling: this makes it so that polygons facing away from you aren't drawn, and if you look at something from behind it would disappear.

Are your enemies sprites or models? Judging by the 90' increments, I would hazard a guess you're drawing 4-view sprites? If so, look into billboarding. It might help with a thing or two. ;)

Share this post


Link to post
Share on other sites
I'm using 3D models, milkshape ascii for now cause thats all I can get to work. I'm trying to find animated model code, but having very little success.

Jake

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!