Sign in to follow this  

Transformation Problems

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

could someone please help, i am finding it difficult to work around moving individual models, i can only move the whole scene. i cant seem to work around moving models that have been selected....Any ideas please

this is my display method....the translate enable me to drag the whole scene(which is not exactly what i want...which is moving a selected object)....seems placing a translate in this function moves the camera instead of the selected models....

[code]

void display(void)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // This clear the background color to dark blue
glMatrixMode(GL_MODELVIEW); // Modeling transformation
glPushMatrix(); glLoadIdentity(); // Initialize the model matrix as identity
glTranslatef(mouse1.GetX(), mouse1.GetY(), 0.0);
drawModel(GL_RENDER);
glPopMatrix();
glFlush();
glutSwapBuffers();

}
[/code]

this is where the selection is done,i have tried every scenario i could but i cant get the selected model to move individually, or how i could include the pushMatrix,gltranslate and popmatrix....to achieve what i want....thank you.
[code]

mouse(int button, int state, int x, int y)
{
GLuint selectBuf[SIZE];
GLint hits;
GLint viewport[4];

mouse1.SetState(button, state);
mouse1.SetNewPos(x, y);
printf("Mouse %s At %d %d\n", (state == GLUT_DOWN) ? "Down" : "Up", x, y);

if (button == GLUT_LEFT_BUTTON && glutGetModifiers() & GLUT_ACTIVE_SHIFT)
button = GLUT_MIDDLE_BUTTON;



if(button==GLUT_LEFT_BUTTON && state== GLUT_DOWN)
{

glGetIntegerv(GL_VIEWPORT,viewport);
glSelectBuffer(SIZE, selectBuf);
glRenderMode(GL_SELECT);

glInitNames();
glPushName(-1);

glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();

gluPickMatrix((GLdouble) x, (GLdouble) (viewport[3] - y), 5.0, 5.0, viewport);
gluPerspective(45.0f,(GLfloat)screen_width/(GLfloat)screen_height,0.1f,10000.0f);

drawModel(GL_SELECT);


glMatrixMode (GL_PROJECTION);

glPopMatrix();
glFlush();

hits = glRenderMode(GL_RENDER);

processHits(hits, selectBuf);

glutPostRedisplay();



}

}
[/code]


thank you for your help

Share this post


Link to post
Share on other sites
[quote name='GottiJay' timestamp='1310467545' post='4834228']
could someone please help, i am finding it difficult to work around moving individual models, i can only move the whole scene. i cant seem to work around moving models that have been selected....Any ideas please

this is my display method....the translate enable me to drag the whole scene(which is not exactly what i want...which is moving a selected object)....seems placing a translate in this function moves the camera instead of the selected models....

[code]

void display(void)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // This clear the background color to dark blue
glMatrixMode(GL_MODELVIEW); // Modeling transformation
glPushMatrix(); glLoadIdentity(); // Initialize the model matrix as identity
glTranslatef(mouse1.GetX(), mouse1.GetY(), 0.0);
drawModel(GL_RENDER);
glPopMatrix();
glFlush();
glutSwapBuffers();

}
[/code]

this is where the selection is done,i have tried every scenario i could but i cant get the selected model to move individually, or how i could include the pushMatrix,gltranslate and popmatrix....to achieve what i want....thank you.
[code]

mouse(int button, int state, int x, int y)
{
GLuint selectBuf[SIZE];
GLint hits;
GLint viewport[4];

mouse1.SetState(button, state);
mouse1.SetNewPos(x, y);
printf("Mouse %s At %d %d\n", (state == GLUT_DOWN) ? "Down" : "Up", x, y);

if (button == GLUT_LEFT_BUTTON && glutGetModifiers() & GLUT_ACTIVE_SHIFT)
button = GLUT_MIDDLE_BUTTON;



if(button==GLUT_LEFT_BUTTON && state== GLUT_DOWN)
{

glGetIntegerv(GL_VIEWPORT,viewport);
glSelectBuffer(SIZE, selectBuf);
glRenderMode(GL_SELECT);

glInitNames();
glPushName(-1);

glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();

gluPickMatrix((GLdouble) x, (GLdouble) (viewport[3] - y), 5.0, 5.0, viewport);
gluPerspective(45.0f,(GLfloat)screen_width/(GLfloat)screen_height,0.1f,10000.0f);

drawModel(GL_SELECT);


glMatrixMode (GL_PROJECTION);

glPopMatrix();
glFlush();

hits = glRenderMode(GL_RENDER);

processHits(hits, selectBuf);

glutPostRedisplay();



}

}
[/code]


thank you for your help
[/quote]

You should stick the translation in your DrawModel function on a per model basis other wise it will effect all models drawn by the main render loop

Share this post


Link to post
Share on other sites
[code]


ObjLoad ("reflector2.3ds","texture.bmp", 10.0, 20.0, -500.0, 900,0,0);

ObjLoad ("mast2.3ds","texture.bmp", 20.0, 10.0, -500.0, 900,0,0);

ObjLoad ("receiver4.3ds","texture.bmp", 0.0, 0.0, -500.0, 900,0,0);

ObjLoad ("connector.3ds","texture.bmp", -10.0, 10.0, -500.0, 900,0,0);

ObjLoad ("chesspawn.3ds","texture.bmp", -20.0, 10.0, -500.0, 900,0,0);

ObjLoad ("stand2.3ds","texture.bmp", -30.0, 10.0, -500.0, 900,0,0);


[/code]

or could i still further put the translation in the draw function, wil it still be okay

glTranslatef(locationlist[i][0],
locationlist[i][1],
locationlist[i][2]);



[code]


void drawModel(GLenum mode)

{

int i,j;

for (i=0;i<obj_qty;i++)

{

glPushMatrix(); // We save the current matrix

glTranslatef(locationlist[i][0],
locationlist[i][1],
locationlist[i][2]);






glMultMatrixf(&object[i].matrix[0][0]); // Now let's multiply the object matrix by the identity-first matrix


if (object[i].id_texture!=-1)

{

glBindTexture(GL_TEXTURE_2D, object[i].id_texture); // We set the active texture

glEnable(GL_TEXTURE_2D); // Texture mapping ON

}

else

glDisable(GL_TEXTURE_2D); // Texture mapping OFF

if(mode == GL_SELECT) glLoadName(i);

glBegin(GL_TRIANGLES); // glBegin and glEnd delimit the vertices that define a primitive (in our case triangles)

for (j=0;j<object[i].polygons_qty;j++)

{

//----------------- FIRST VERTEX -----------------

//Normal coordinates of the first vertex

glNormal3f( object[i].normal[ object[i].polygon[j].a ].x,

object[i].normal[ object[i].polygon[j].a ].y,

object[i].normal[ object[i].polygon[j].a ].z);

// Texture coordinates of the first vertex

glTexCoord2f( object[i].mapcoord[ object[i].polygon[j].a ].u,

object[i].mapcoord[ object[i].polygon[j].a ].v);

// Coordinates of the first vertex

glVertex3f( object[i].vertex[ object[i].polygon[j].a ].x,

object[i].vertex[ object[i].polygon[j].a ].y,

object[i].vertex[ object[i].polygon[j].a ].z);


[/code]

thanks for your help

Share this post


Link to post
Share on other sites
[quote name='GottiJay' timestamp='1310473015' post='4834260']
[code]


ObjLoad ("reflector2.3ds","texture.bmp", 10.0, 20.0, -500.0, 900,0,0);

ObjLoad ("mast2.3ds","texture.bmp", 20.0, 10.0, -500.0, 900,0,0);

ObjLoad ("receiver4.3ds","texture.bmp", 0.0, 0.0, -500.0, 900,0,0);

ObjLoad ("connector.3ds","texture.bmp", -10.0, 10.0, -500.0, 900,0,0);

ObjLoad ("chesspawn.3ds","texture.bmp", -20.0, 10.0, -500.0, 900,0,0);

ObjLoad ("stand2.3ds","texture.bmp", -30.0, 10.0, -500.0, 900,0,0);


[/code]

or could i still further put the translation in the draw function, wil it still be okay

glTranslatef(locationlist[i][0],
locationlist[i][1],
locationlist[i][2]);



[code]


void drawModel(GLenum mode)

{

int i,j;

for (i=0;i<obj_qty;i++)

{

glPushMatrix(); // We save the current matrix

glTranslatef(locationlist[i][0],
locationlist[i][1],
locationlist[i][2]);






glMultMatrixf(&object[i].matrix[0][0]); // Now let's multiply the object matrix by the identity-first matrix


if (object[i].id_texture!=-1)

{

glBindTexture(GL_TEXTURE_2D, object[i].id_texture); // We set the active texture

glEnable(GL_TEXTURE_2D); // Texture mapping ON

}

else

glDisable(GL_TEXTURE_2D); // Texture mapping OFF

if(mode == GL_SELECT) glLoadName(i);

glBegin(GL_TRIANGLES); // glBegin and glEnd delimit the vertices that define a primitive (in our case triangles)

for (j=0;j<object[i].polygons_qty;j++)

{

//----------------- FIRST VERTEX -----------------

//Normal coordinates of the first vertex

glNormal3f( object[i].normal[ object[i].polygon[j].a ].x,

object[i].normal[ object[i].polygon[j].a ].y,

object[i].normal[ object[i].polygon[j].a ].z);

// Texture coordinates of the first vertex

glTexCoord2f( object[i].mapcoord[ object[i].polygon[j].a ].u,

object[i].mapcoord[ object[i].polygon[j].a ].v);

// Coordinates of the first vertex

glVertex3f( object[i].vertex[ object[i].polygon[j].a ].x,

object[i].vertex[ object[i].polygon[j].a ].y,

object[i].vertex[ object[i].polygon[j].a ].z);


[/code]

thanks for your help
[/quote]


That should be fine as long as the matrices for the selected object is different from the rest, like the rest has a transform of identity and the selected one has a different one.

Share this post


Link to post
Share on other sites
[quote name='GottiJay' timestamp='1310473015' post='4834260']
[code]


ObjLoad ("reflector2.3ds","texture.bmp", 10.0, 20.0, -500.0, 900,0,0);

ObjLoad ("mast2.3ds","texture.bmp", 20.0, 10.0, -500.0, 900,0,0);

ObjLoad ("receiver4.3ds","texture.bmp", 0.0, 0.0, -500.0, 900,0,0);

ObjLoad ("connector.3ds","texture.bmp", -10.0, 10.0, -500.0, 900,0,0);

ObjLoad ("chesspawn.3ds","texture.bmp", -20.0, 10.0, -500.0, 900,0,0);

ObjLoad ("stand2.3ds","texture.bmp", -30.0, 10.0, -500.0, 900,0,0);


[/code]

or could i still further put the translation in the draw function, wil it still be okay

glTranslatef(locationlist[i][0],
locationlist[i][1],
locationlist[i][2]);



[code]


void drawModel(GLenum mode)

{

int i,j;

for (i=0;i<obj_qty;i++)

{

glPushMatrix(); // We save the current matrix

glTranslatef(locationlist[i][0],
locationlist[i][1],
locationlist[i][2]);






glMultMatrixf(&object[i].matrix[0][0]); // Now let's multiply the object matrix by the identity-first matrix


if (object[i].id_texture!=-1)

{

glBindTexture(GL_TEXTURE_2D, object[i].id_texture); // We set the active texture

glEnable(GL_TEXTURE_2D); // Texture mapping ON

}

else

glDisable(GL_TEXTURE_2D); // Texture mapping OFF

if(mode == GL_SELECT) glLoadName(i);

glBegin(GL_TRIANGLES); // glBegin and glEnd delimit the vertices that define a primitive (in our case triangles)

for (j=0;j<object[i].polygons_qty;j++)

{

//----------------- FIRST VERTEX -----------------

//Normal coordinates of the first vertex

glNormal3f( object[i].normal[ object[i].polygon[j].a ].x,

object[i].normal[ object[i].polygon[j].a ].y,

object[i].normal[ object[i].polygon[j].a ].z);

// Texture coordinates of the first vertex

glTexCoord2f( object[i].mapcoord[ object[i].polygon[j].a ].u,

object[i].mapcoord[ object[i].polygon[j].a ].v);

// Coordinates of the first vertex

glVertex3f( object[i].vertex[ object[i].polygon[j].a ].x,

object[i].vertex[ object[i].polygon[j].a ].y,

object[i].vertex[ object[i].polygon[j].a ].z);


[/code]

thanks for your help
[/quote]


thanks alot i did see some improved changes, i am trying to achieve a drag object property in my program, i had in place of gltranslate used [size="2"]ObjTranslate(&object[obj_control],mouse1.GetX(), mouse1.GetY(), 0.0); in my program earlier to help me achieve dragging....only for my objects to disappear (probably translating the selected objects to locations not in the scene).......which brought me to feel my algorithm was wrong....i tested it with the function (without using my drag algorithm)[size="2"]ObjTranslate(&object[obj_control],0.0, 0.0, -1); the model moved a step on each click.

could you please give me an idea how i could incorporate dragging of objects in my program or an algorithm i could use...i am really bad at maths


thank you very much

[/size]

[/size]

Share this post


Link to post
Share on other sites
I don't know GL as well as I should anymore but what you would like to do is the following.


[code]

Setup Projection and view matrices

Foreach model in modelsList

{

setup the world matrix of this model

draw the model itself

}

[/code]


I have no idea what your object and all the arrays stand for keep your code simple it will help you understand what you are doing or trying to do without seeing the code for it.

Share this post


Link to post
Share on other sites

This topic is 2348 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this