I have the basic idea of openGL and I decided it was better to use SDL (for input and such) with openGL (for graphics rendering), and all I have right now is one cube with a texture displayed
now here is the point of this:
I have the shape displayed at a point on the screen and I want it to be able to face the mouse but I can't figure out how to do so... I'm not the best at math but I do understand most of what I'm told
Here is some of my code that I've been using:
float pointto(float x1, float y1, float x2, float y2){float n1 = sqrt(x1*x1+y1*y1);float n2 = sqrt(x2*x2+y2*y2);float angle = acos((x1*x2+y1*y2)/(n1*n2)) * 180 / PI;return angle;}//////////////////////////////////////////////////////////////////void DisplayImage(double x, double y, SDL_Surface* image, GLuint textr, double angle, double scale = 1, bool center=false){ glLoadIdentity(); glTranslatef(x,y,0); glRotatef(angle,0.0f,0.0f,1.0f); glBindTexture(GL_TEXTURE_2D, textr); glBegin(GL_QUADS); if (center == true) { glTexCoord2f(0.0f, 0.0f); glVertex3f(-(image->w/2)*scale, -(image->h/2)*scale,0); glTexCoord2f(1.0f, 0.0f); glVertex3f((image->w/2)*scale, -(image->h/2)*scale, 0); glTexCoord2f(1.0f, 1.0f); glVertex3f((image->w/2)*scale, (image->h/2)*scale, 0); glTexCoord2f(0.0f, 1.0f); glVertex3f(-(image->w/2)*scale, (image->h/2)*scale, 0); } else { glTexCoord2f(0.0f, 0.0f); glVertex3f(1*scale, 1*scale,0); glTexCoord2f(1.0f, 0.0f); glVertex3f(image->w*scale, 1*scale, 0); glTexCoord2f(1.0f, 1.0f); glVertex3f(image->w*scale, image->h*scale, 0); glTexCoord2f(0.0f, 1.0f); glVertex3f(1*scale, image->h*scale, 0); } glEnd();}///////////////////////////////////////////////////////////////////////////// in my main function DisplayImage(100,100,zombie1,texture2, pointto(100,100,mouseX,mouseY),1,true);
that gets it to wiggle on the Z axis a little (I do want the z axis) but it doesn't face the mouse... what am I doing wrong?
[SIDE NOTE]
mouseX and mouseY are stored in INT because of sdl... could that be a problem?