iverson1407

04-20-2011, 07:54 AM

I have a question about a special case translating from screen coordinates to world coordinates.

I wanna do with a interactive particle system.

So that we can click on the screen and emit some particles.

I've come through a lot of comments on this topic. However my case is a little tricky..

I just wanna get the coordinates with a given z axis value of world coordinate.

for example, I wanna get the world coordinate from the screen given the z = -5.0.

How can I do that? Can you help me with some codes?

My initialized and configuration function is as the following:

void initRendering()

{

glEnable(GL_DEPTH_TEST);

glEnable(GL_DEPTH);

}

void handleResize(int w,int h)

{

glViewport(0,0,w,h);

glMatrixMode(GL_PROJECTION);

glLoadIdentity();

gluPerspective(45.0,(double)w/(double)h,1.0,200.0);

}

void drawscene()

{

float a = 0.0f;

float b = 0.0f;

float c = 0.0f;

particle *p;

particle *p2;

if(e->particlecount!=0)

{

p = e->anchorparticle->next;

}

if(e2->particlecount!=0)

{

p2 = e2->anchorparticle->next;

}

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

glMatrixMode(GL_MODELVIEW);

glLoadIdentity();

glPointSize(2.0f);

glPushMatrix();

.......

glPopMatrix()

}

Thx in advance for people who will help me.Thx very much.

I wanna do with a interactive particle system.

So that we can click on the screen and emit some particles.

I've come through a lot of comments on this topic. However my case is a little tricky..

I just wanna get the coordinates with a given z axis value of world coordinate.

for example, I wanna get the world coordinate from the screen given the z = -5.0.

How can I do that? Can you help me with some codes?

My initialized and configuration function is as the following:

void initRendering()

{

glEnable(GL_DEPTH_TEST);

glEnable(GL_DEPTH);

}

void handleResize(int w,int h)

{

glViewport(0,0,w,h);

glMatrixMode(GL_PROJECTION);

glLoadIdentity();

gluPerspective(45.0,(double)w/(double)h,1.0,200.0);

}

void drawscene()

{

float a = 0.0f;

float b = 0.0f;

float c = 0.0f;

particle *p;

particle *p2;

if(e->particlecount!=0)

{

p = e->anchorparticle->next;

}

if(e2->particlecount!=0)

{

p2 = e2->anchorparticle->next;

}

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

glMatrixMode(GL_MODELVIEW);

glLoadIdentity();

glPointSize(2.0f);

glPushMatrix();

.......

glPopMatrix()

}

Thx in advance for people who will help me.Thx very much.