Hi again!!!
After alot of work , i've just finished my object_cache class! which creates and draws objects (some triangles!!) at runtime(yes, you guessed right , im trying to make a mini-level editor).
The rendering works fine.
The only problem that im having is with objects position!
To make things easier , i'll post some code :
Thats the function that adds the new object to our vector...
void sOBJECT_CACHE::Add_object(GLfloat tx,GLfloat ty,GLfloat tz)
{
TRIANGLE TEMP;//a normal 3d triangle..
triangle_list.push_back(TEMP);//add the temp object
triangle_list[TOTAL].repos(tx,ty,tz);//set the new position based on camera's
//position!
TOTAL+=1;//increase the list..
}
Camera class:
#include "cCAMERA.h"
#include <math.h>
//WARNING!SOME CODE IS TAKEN FROM NEHE'S TUTORIALS!!
CAMERA::CAMERA()
{
heading=0.0f;
walkbias = 0;
walkbiasangle = 0;
lookupdown = 0.0f;
z=-20.0f;
xpos=0.0f;
zpos=0.0f;
lookupdown=0.0f;
}
void CAMERA::CAM_DO_UPDATE()
{
GLfloat xtrans = -xpos;
GLfloat ztrans = -zpos;
GLfloat ytrans = -walkbias - 0.25f;
GLfloat sceneroty = 360.0f - yrot;
glRotatef( lookupdown, 1.0f, 0.0f , 0.0f );
glRotatef( sceneroty, 0.0f, 1.0f , 0.0f );
glTranslatef( xtrans, ytrans, ztrans );
}
void CAMERA::CamBW()
{
xpos += ( float )sin( yrot * PI180 ) * 0.05f;
zpos += ( float )cos( yrot * PI180 ) * 0.05f;
if ( walkbiasangle <= 1.0f )
walkbiasangle = 359.0f;
else
walkbiasangle -= 10;
walkbias = ( float )sin( walkbiasangle * PI180 ) / 10.0f;
}
void CAMERA::CamFW()
{
xpos -= ( float )sin( yrot * PI180 ) * 0.05f;
zpos -= ( float )cos( yrot * PI180 ) * 0.05f;
if ( walkbiasangle >= 359.0f )
walkbiasangle = 0.0f;
else
walkbiasangle+= 10;
walkbias = ( float )sin( walkbiasangle * PI180 ) / 10.0f;
}
void CAMERA::CamLeft()
{
// yrot+=1.5f;
heading += 1.5f/2;
yrot = heading;
}
void CAMERA::CamRight()
{
//yrot-=1.5f;
heading -= 1.5f/2;
yrot = heading;
}
void CAMERA::CamScrollRight()
{
xpos-= - (0.5f/10);
}
void CAMERA::CamScrollLeft()
{
xpos+= - (0.5f/10);
}
GLfloat CAMERA:: GET_X()
{
return -xpos;
}
GLfloat CAMERA:: GET_Z()
{
return -zpos;
}
GLfloat CAMERA:: GET_Y()
{
return -0.0f;//....Any way to fix this ? xD
}
...AND THE MOST IMPORTANT PART...
//thats how im doing it..
if( EVENTS.button.button == SDL_BUTTON_LEFT )
{
OBJECT_CACHE_CLASS.Add_object(c_CAMERA.GET_X(),c_CAMERA.GET_Y(),c_CAMERA.GET_Z());
}
Can someone tell me what im doing wrong/??????????????????????????????!!!
edited
Here's a picture:
http://img443.imageshack.us/img443/4623/damnitse3.jpg