Jump to content
  • Advertisement
Sign in to follow this  

Mapping Selected Objects

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

Hi guys , i having a little problem with mapping objects picked so that i could drag them. the selection is working okay(i tested it)....but i dont know how to extract the nearest object picked and perform dragging...

i tried doing some dragging but ended up dragging the whole lot of models, but my intention is to drag individually.

i could move individual models with the keyboard but that does not involve picking which is fine, i just want to be able to drag individually...how do i map these two picking and draging

thank you


""""i tried to put my code here but its unreadable,..it keeps including font poperties in them""""

if any body has any idea...please help thanks

Share this post


Link to post
Share on other sites
Advertisement
Hidden

[color="#0000ff"][color="#0000ff"]void processHits(GLint hits, GLuint buffer[])

{

[color="#0000ff"][color="#0000ff"]unsigned [color="#0000ff"][color="#0000ff"]int i, j;

GLuint ii,jj,names,*ptr;

printf([color="#a31515"][color="#a31515"]"hits =%d\n", hits);

ptr = (GLuint *) buffer;

[color="#0000ff"][color="#0000ff"]for (i=0; i<hits; i++)

{

names = *ptr;

ptr+=3;

[color="#0000ff"][color="#0000ff"]for(j=0; j<names; j++)

{

[color="#0000ff"][color="#0000ff"]if(*ptr==0)printf([color="#a31515"][color="#a31515"]"REFLECTOR SELECTED\n");

[color="#0000ff"][color="#0000ff"]else [color="#0000ff"][color="#0000ff"]if(*ptr==1)printf([color="#a31515"][color="#a31515"]"MAST SELECTED\n");

[color="#0000ff"][color="#0000ff"]else [color="#0000ff"][color="#0000ff"]if(*ptr==2)printf([color="#a31515"][color="#a31515"]"RECEIVER SELECTED\n");

[color="#0000ff"][color="#0000ff"]else [color="#0000ff"][color="#0000ff"]if(*ptr==3)printf([color="#a31515"][color="#a31515"]"CONNECTOR SELECTED\n");

[color="#0000ff"][color="#0000ff"]else [color="#0000ff"][color="#0000ff"]if(*ptr==4)printf([color="#a31515"][color="#a31515"]"CHESSPAWN SELECTED\n");

[color="#0000ff"][color="#0000ff"]else printf ([color="#a31515"][color="#a31515"]"STAND rectangle\n");

ptr++;

}

printf([color="#a31515"][color="#a31515"]"\n");

}

}

[color="#0000ff"][color="#0000ff"]#define SIZE 512





[color="#0000ff"][color="#0000ff"]bool down=[color="#0000ff"][color="#0000ff"]false;

[color="#0000ff"][color="#0000ff"]void

mouse([color="#0000ff"][color="#0000ff"]int button, [color="#0000ff"][color="#0000ff"]int state, [color="#0000ff"][color="#0000ff"]int x, [color="#0000ff"][color="#0000ff"]int y)

{

GLuint selectBuf[SIZE];

GLint hits;

GLint viewport[4];

[color="#0000ff"][color="#0000ff"]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);

[color="#008000"][color="#008000"]//gluOrtho2D(-2.0, 2.0, -2.0, 2.0);

drawModel(GL_SELECT);

glMatrixMode (GL_PROJECTION);

glPopMatrix();

glFlush();

hits = glRenderMode(GL_RENDER);

processHits(hits, selectBuf);

oldX = x;

oldY = y;

down=[color="#0000ff"][color="#0000ff"]true;

glutPostRedisplay();

}

[color="#0000ff"][color="#0000ff"]else {

down=[color="#0000ff"][color="#0000ff"]false;

}

[color="#008000"][color="#008000"]//if(obj_control>0 && obj_control<= 6)

[color="#008000"][color="#008000"]//ObjTranslate(&object[obj_control],pan_x,pan_y,0);



}















[color="#008000"][color="#008000"]/*

if (button != GLUT_LEFT_BUTTON || state != GLUT_DOWN)

{

cursorX = x;

cursorY = y;

mode = SELECT;

}



Share this post


Link to post
Please edit the OP by removing and re-pasting the code snippet. Make sure to paste it as raw text and wrap it then with tags. Pasting it as raw text may require you to first paste the snippet into a basic text editor (i.e. where syntax coloring and such is not used) and copy it from there.

In general: When the picking ray hits several objects, simply chose the one that is hit in the point closest to the origin of the ray and on the positive side of the track.

Share this post


Link to post
Share on other sites

""""i tried to put my code here but its unreadable,..it keeps including font poperties in them""""

if any body has any idea...please help thanks

As written above: Paste only raw text. It must not have different sizes, text coloring, weighting, styles, ... Perhaps your Browser has a function "paste and adapt style" or something similar. Or else try the indirection using another, simple text editor to paste the text to and copy it from there as raw text.

Share this post


Link to post
Share on other sites

[quote name='GottiJay' timestamp='1310205409' post='4833028']
""""i tried to put my code here but its unreadable,..it keeps including font poperties in them""""

if any body has any idea...please help thanks

As written above: Paste only raw text. It must not have different sizes, text coloring, weighting, styles, ... Perhaps your Browser has a function "paste and adapt style" or something similar. Or else try the indirection using another, simple text editor to paste the text to and copy it from there as raw text.
[/quote]



void processHits(GLint hits, GLuint buffer[])
{
unsigned int i, j;
GLuint ii,jj,names,*ptr;

printf("hits =%d\n", hits);
ptr = (GLuint *) buffer;
for (i=0; i<hits; i++)
{
names = *ptr;
ptr+=3;
for(j=0; j<names; j++)
{
if(*ptr==0)printf("REFLECTOR SELECTED\n");
else if(*ptr==1)printf("MAST SELECTED\n");
else if(*ptr==2)printf("RECEIVER SELECTED\n");
else if(*ptr==3)printf("CONNECTOR SELECTED\n");
else if(*ptr==4)printf("CHESSPAWN SELECTED\n");
else printf ("STAND rectangle\n");
ptr++;
}
printf("\n");
}
}

#define SIZE 512



bool down=false;

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

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);
//gluOrtho2D(-2.0, 2.0, -2.0, 2.0);
drawModel(GL_SELECT);

glMatrixMode (GL_PROJECTION);
glPopMatrix();
glFlush();

hits = glRenderMode(GL_RENDER);

processHits(hits, selectBuf);

oldX = x;
oldY = y;
down=true;
glutPostRedisplay();
}
else {
down=false;
}
//if(obj_control>0 && obj_control<= 6)
//ObjTranslate(&object[obj_control],newX,newY,0);

}



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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!