Sign in to follow this  
OgbobeBuko

Mapping Selected Objects

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
Hidden
[code]
[size="2"][color="#0000ff"][size="2"][color="#0000ff"]void[/color][/size][/color][/size][size="2"] processHits(GLint hits, GLuint buffer[])

{

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

GLuint ii,jj,names,*ptr;

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

ptr = (GLuint *) buffer;

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

{

names = *ptr;

ptr+=3;

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

{

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

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

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

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

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

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

ptr++;

}

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

}

}

[/size][size="2"][color="#0000ff"][size="2"][color="#0000ff"]#define[/color][/size][/color][/size][size="2"] SIZE 512





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

[/size][size="2"][color="#0000ff"][size="2"][color="#0000ff"]void

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

{

GLuint selectBuf[SIZE];

GLint hits;

GLint viewport[4];

[/size][size="2"][color="#0000ff"][size="2"][color="#0000ff"]if[/color][/size][/color][/size][size="2"](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);

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

[/color][/size][/color][/size][size="2"]drawModel(GL_SELECT);

glMatrixMode (GL_PROJECTION);

glPopMatrix();

glFlush();

hits = glRenderMode(GL_RENDER);

processHits(hits, selectBuf);

oldX = x;

oldY = y;

down=[/size][size="2"][color="#0000ff"][size="2"][color="#0000ff"]true[/color][/size][/color][/size][size="2"];

glutPostRedisplay();

}

[/size][size="2"][color="#0000ff"][size="2"][color="#0000ff"]else[/color][/size][/color][/size][size="2"] {

down=[/size][size="2"][color="#0000ff"][size="2"][color="#0000ff"]false[/color][/size][/color][/size][size="2"];

}

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

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

[/color][/size][/color][/size][size="2"]

}















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

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

{

cursorX = x;

cursorY = y;

mode = SELECT;

}

[/color][/size][/color][/size]

[/code]

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 [code] 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
[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
[/quote]
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='haegarr' timestamp='1310207531' post='4833035']
[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
[/quote]
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]


[code]
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);

}



[/code]

Share this post


Link to post
Share on other sites

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