View Full Version : finding current position

joao flavio

09-10-2012, 04:49 PM

Does opengl provide a way to find the current point with respect to the original frame? For

instance, in a routine to assemble a pipe system from its basic components, one may need

to keep track of branches' points. Is it possible to find the current position after several

callings to gltranslatef() and glrotated()? I would really apreciate any help.

Thank you.

Rosario Leonardi

09-10-2012, 05:21 PM

Let me understand.

You have something like

glloadmatrix(cameraMatrix)

gltranslate

glrotate

glrotate

glmultmatrix

gltranlate

gltranslate

and you want the current position here?

The current position in work reference? In view space? relative to another (parent) node? Of with point?

In word reference:

glGetMatrix(GL_MODELVIEW_MATRIX, matrix);

worldMatrix = inverse(cameraMatrix) * matrix

In view space:

glGetMatrix(GL_MODELVIEW_MATRIX, matrix);

for a parent node just multiply the inverse of the parent matrix by the matrix you got from glgetmatrix

by the way... glGetMatrix is really slow, don't use it, don't use glTranslate and glRotate either, do your math by yourself and cache your matrix, it will be a lot faster.

Kopelrativ

09-10-2012, 09:37 PM

There is the technique of using a deferred shader (http://ephenationopengl.blogspot.se/2012/01/setting-up-deferred-shader.html). It may be overkill, or it maybe what you want. In principle, you do the rendering in two steps (or more). You define a Framebuffer Object (http://www.opengl.org/wiki/Framebuffer_Object) with several render targets. In those targets, you save information, like position, normals, lighting, etc. In the second stage, you render the result to the screen, accessing the previous render targets as bitmaps.

Regardless, consider to not use deprecated legacy OpenGL (http://www.opengl.org/wiki/Legacy_OpenGL).

V-man

09-11-2012, 04:28 AM

Does opengl provide a way to find the current point with respect to the original frame? For

instance, in a routine to assemble a pipe system from its basic components, one may need

to keep track of branches' points. Is it possible to find the current position after several

callings to gltranslatef() and glrotated()? I would really apreciate any help.

Thank you.

There is no such thing

glGetMatrix(GL_MODELVIEW_MATRIX, matrix);

Kopelrativ meant to say

Use glGetFloatv(GL_MODELVIEW_MATRIX, matrix);

which you can use.

Some people don't realize this, but that is just matrix math which anyone can perform. In fact, it is better to use a math library

http://www.opengl.org/wiki/Related_toolkits_and_APIs#Math_Libraries

dukey

09-11-2012, 04:59 AM

Sure, assuming your view position is 0,0,0 just multiply that point by the model view matrix

joao flavio

09-12-2012, 08:03 PM

Thank you, I guess that's what I need. Not sure I understood what the code glloadmatrix(cameraMatrix) does, Sorry, I'm not yet familiar with opengl coding!

joao flavio

09-12-2012, 08:07 PM

Thank you for replying.

Powered by vBulletin® Version 4.2.5 Copyright © 2018 vBulletin Solutions Inc. All rights reserved.