Jump to content
  • Advertisement
Sign in to follow this  
levjs

Problem With View!!

This topic is 4863 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

Hello, I have been working on a game where you are a ship and you fly around a screen with asteriods, and an alien base, there's no point yet, because i've run into a problem. There is a boundary, and when the ship aproaches the boundary, I want the camera to stop, so the space beyond the boundary is not visible, and then the ship can run up against the side of screen. Like any normal thing. In other words, i want the ship to stop against the edge like this | | |<> | | | instead of this     |     |     |     |<>     |     | I don't want the ship to continue to be in the center of the screen when it aproaches the boundary. Well, i thought that would be simple enough, just stop moving the camera, right??? NOT Instead, when the ship hits the line at which the camera stops moving, it speeds up, and moves off the screen. Here's that part of my code, I know it's not great, it's the first thing like this i've attempted. But here it is.
	
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);	// Clear Screen And Depth Buffer
	if(x<=350&&x>=-350)xcam=x;
	else xcam=xcam;
	if(y<=350&&y>=-350)ycam=y;
	else ycam=ycam;
	if(x>=400)x=399.9f;
	if(x<=-400)x=-399.9f;
	if(y>=400)y=399.9f;
	if(y<=-400)y=-399.9f;
	xturn=(float)sin(rotshipcontrol*Magic) * 0.05f;
	yturn=(float)cos(rotshipcontrol*Magic) * 0.05f;
	//BACKGROUND
	glLoadIdentity();									// Reset The Current Modelview Matrix
	gluLookAt(xcam,ycam,100,xcam,ycam,0,0,1,0);
	glPushMatrix();
	glBindTexture(GL_TEXTURE_2D,texture[0]);
	glBegin(GL_QUADS);
		glTexCoord2f(1,1);glVertex3f(400,400,0);
		glTexCoord2f(0,1);glVertex3f(-400,400,0);
		glTexCoord2f(0,0);glVertex3f(-400,-400,0);
		glTexCoord2f(1,0);glVertex3f(400,-400,0);
	glEnd();
	 glPopMatrix();
	//END BACKGROUND
if(!dead)
{
	glPushMatrix(); 
	glTranslatef(x ,y,80);
	glRotatef(rotshipcontrol,0,0,1);
	//glRotatef(rotship,0,1,0);
	Ship->draw();
	if(tailf)DrawTail();
	glPopMatrix();
}
	DrawAsteriods();
	DrawBase();
	DrawWeapons();
	timer++;
	rotship+=0.3f;
	return TRUE;
}


I know it has something to do with how i'm pushing and popping the matrix, but i can't figure it out. Any help would be greatly appreciated. Thanks an awful lot. Levi

Share this post


Link to post
Share on other sites
Advertisement
suround the scene with planes (you know) Ax+By+Cz+D = 0
anyways before each time u move the camera see if will take it to within X units of one of the planes if it does then dont move the camera

Share this post


Link to post
Share on other sites
i'm sorta doing that, just without the planes. As i said, it's not a problem with not moving the camera, it's just that once the camera stops, the ship starts acting weird. The trail of the engine does fine. I think it has something to do with this. The ship is placed at (x,y,80), while everything else is placed at (<something>,<something>,0). Would this cause it to malfunction. Basically, once the camera movement stops, the ship starst going twice as fast as it did, but only on the axis that it is over the boundary on. For example, if it goes over my boundary on the x axis, the camera stops, and the ship stars moving faster.
I'll see if i can get a screenshot of what it looks like. Any other help would be great.
Levi

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!