rotating using trig functions

Started by
11 comments, last by Tom Sloper 5 years, 5 months ago

well rutin has helped with this problem, but I wanted to get more input. I am still working on my rotation algorithm. I want my bullet sprite to rotate around my plane sprite and shoot in the same direction as my plane is facing.


	glTexCoord3f(0.0f, 0.0f, 0.0f);

	glVertex3f(cos(angle) - sin(angle), sin(angle) + cos(angle), 0.0f);
	glTexCoord3f(1.0f, 0.0f, 0.0f);

	glVertex3f(cos(angle) - sin(angle), sin(angle) + cos(angle), 0.0f);
	glTexCoord3f(1.0f, 1.0f, 0.0f);

	glVertex3f(cos(angle) - sin(angle), sin(angle) + cos(angle), 0.0f);
	glTexCoord3f(0.0f, 1.0f, 0.0f);

	glVertex3f(cos(angle) - sin(angle), sin(angle) + cos(angle), 0.0f);
	glEnd();

here is the code I am using.

Advertisement

When posting a question, what are you supposed to include in the post?

Hint: You've been told probably a dozen times or more.

Hello to all my stalkers.

Link to the previous discussion where this likely should be discussed anyway instead of in a new topic on the same subject would be helpful to see what has been done already.  I also agree with @Lactose, you've been told how to compose "questions" before, it's not difficult in the least either.  Also, comment your code!  What have you done to debug it?  What does that code even do?  What is your problem?  What is not happening?  Extracting information from you is much like getting blood from a rock.

"Those who would give up essential liberty to purchase a little temporary safety deserve neither liberty nor safety." --Benjamin Franklin

well my problem is that I want my bullet sprite to shoot in the direction my plane is facing, I have managed to get  the plane to face  and move in all directions. at least I have got that to work. right now my code only draws a bullet in the up direction.

well I am working on understanding rotation, the matrix [cos theta -sin theta],[sin theta cos theta] is used to rotate a point around the origin. what I want to know is what the trig functions are multiplied by in order to get the bullet to rotate around the plane sprite, I am also taking a class in linear algebra which is helping me understand matrices and how they operate.

 

when I use the trig matrix I get various identity matrices. I am however trying to draw a polygon that I want to rotate around a point in the coordinate system.

hey @phil67rpg do you break code, meaning do you take code that someone else has written and then mess it up some how?  Change a number, comment out a line and so forth, have you tried that?  Watching what breaking the code does can help you to understand better what the code is actually doing.

well  I am doing this game for a class in college, however my teacher is not very helpful, I am on my own

I have made some progress on my code, am I doing the right thing?


void drawbullet_one()
{
	glEnable(GL_TEXTURE_2D);

	glBindTexture(GL_TEXTURE_2D, texture[2]);

	glPushMatrix();

	glTranslatef(-5.0f, 0.5f, 0.0f);

	glBegin(GL_POLYGON);
	glTexCoord3f(0.0f, 0.0f, 0.0f);

	glVertex3f(0.0625f*cos(angle) - 0.0625f*sin(angle), 0.0625f*sin(angle) + 0.0625f*cos(angle), 0.0f);
	glTexCoord3f(1.0f, 0.0f, 0.0f);

	glVertex3f(-0.0625f*cos(angle) - 0.0625f*sin(angle), 0.0625f*sin(angle) + 0.0625f*cos(angle), 0.0f);
	glTexCoord3f(1.0f, 1.0f, 0.0f);

	glVertex3f(-0.0625f*cos(angle) - 0.0625f*sin(angle), 0.0625f*sin(angle) + -0.0625f*cos(angle), 0.0f);
	glTexCoord3f(0.0f, 1.0f, 0.0f);

	glVertex3f(0.0625f*cos(angle) - 0.0625f*sin(angle), 0.0625f*sin(angle) + -0.0625f*cos(angle), 0.0f);
	glEnd();

	glTranslatef(5.0f, -0.5f, 0.0f);

	glPopMatrix();

	glDisable(GL_TEXTURE_2D);
}

 

This topic is closed to new replies.

Advertisement