Author Topic: I am looking for "x,y,z coordinates" (openGL)  (Read 2505 times)

0 Members and 2 Guests are viewing this topic.

Frankolinox

  • Guest
I am looking for "x,y,z coordinates" (openGL)
« on: June 03, 2014, 09:20:31 AM »
lalala :)
« Last Edit: October 01, 2014, 08:37:10 AM by Frankolinox »

Charles Pegge

  • Guest
Re: I am looking for "x,y,z coordinates" (openGL)
« Reply #1 on: June 03, 2014, 10:56:07 AM »

Do you mean the x y z coordinates of an object after it has been rotated and translated in Opengl? It's not something I've looked at. For dome components, I calculate all the necessary coordinates before any transforms.

Perhaps we should ask Mike how this can be done :)

Mike Lobanovsky

  • Guest
Re: I am looking for "x,y,z coordinates" (openGL)
« Reply #2 on: June 03, 2014, 01:01:54 PM »
Hi,

You cannot query (if that's the meaning of "catch") the orientation, i.e. translation and/or rotation, of vertices in a polygon or of the polygon as a whole once the world transforms have been applied. All this is client-side data that is supposed to be stored, and kept track of, in user-defined variables (usually arrays).

You can only query the server side of OpenGL state machine, i.e. its current states. You would usually do it using the glGet() function. For example, you can get the current state of the OpenGL modelview matrix via a call to glGetFloatv(GL_MODELVIEW_MATRIX, mtxArray) where mtxArray is the pointer to an array of 16 floats (single-precision floating-point values).

You can also query the objects that appear to be at the cursor's current position within the OpenGL window using OpenGL's own facilities. However the techniques for doing so are rather code intensive for the programmer. This is why it will be also more efficient to use custom-coded procedures to keep track of where the objects are if the total polygon count in the scene isn't very high.

Either way, there seem to be no such examples in the current OxygenBasic code base. If you describe what you want to do more precisely, perhaps I will be able to point you to some relevant material on the net. But you will have to create your own Oxygen project for that and be the first one to teach others how to do it in O2. :)

Charles Pegge

  • Guest
Re: I am looking for "x,y,z coordinates" (openGL)
« Reply #3 on: June 03, 2014, 02:10:42 PM »
Thanks Mike,

My understanding of transform matrices is very limited. But is there a way of capturing a current transform matrix, then apply it to a set of coordinates to obtain their transformed positions in space?

Mike Lobanovsky

  • Guest
Re: I am looking for "x,y,z coordinates" (openGL)
« Reply #4 on: June 03, 2014, 05:13:32 PM »
Yes Charles,

Of course you can. glGet() gives you access to the matrix currently selected with glMatrixMode() - either a projection, or modelview, or texture matrix. Conversely, you can always prepare your own matrix and upload it using glLoadMatrix(). The on-screen objects will all be transformed accordingly in the next frame rendered. Naturally this will only be seen if the respective matrix is not cleared to identity at the beginning of the frame.

In fact, immediate-mode OpenGL uses glTranslate() and/or glRotate() calls to operate on the modelview matrix' members atomically. But there's nothing prevents you from uploading a precomputed matrix in one go with glLoadMatrix() in each frame too.

The current modelview matrix that you copy in your own array with a glGetFloatv(GL_MODELVIEW_MATRIX, mtxArray) call can also be used to calculate the current vertex coordinates for all the polygons in a given 3D model (a.k.a. mesh, a.k.a. object) associated with that matrix. That is a simple task for a static object; you just multiply each one of the model's vertices by the matrix.

Compound dynamically moving models are constructed as a hierarchy of objects and are more difficult to calculate. To simplify the calc, modern 3D models are usually split into several dozens of polygon groups (meshes) each of which is spatially bound to one or more parental "bones". The bones are interconnected into a tree-like "skeleton" pretty much like the bones in the skeleton of a living creature. Matrix (or better, quaternion) transforms are applied not to each vertex of the model but rather to the "joints" between the bones in the skeleton, so that each joint drags the associated bone which in its turn drags the associated mesh of polygons in the model. Please run the attached exe for a movie capture of a 3D model and its skeleton as it walks on my desktop in my 3D model viewer. :)

That's why the dynamic actors of a scene such as e.g. players or monsters are conventionally stored in a standard basic state called "T-pose" looking straight ahead, mouth closed, arms spread wide apart at the shoulder level, palms down, legs straight, feet parallel (see the snapshot attached below).

Matrix calc based on OpenGL's current modelview matrix is however computationally intensive so simpler tasks like determining the object under the cursor are usually fulfilled using simpler tweaks that can be performed almost entirely on the GPU.

.

Charles Pegge

  • Guest
Re: I am looking for "x,y,z coordinates" (openGL)
« Reply #5 on: June 04, 2014, 11:48:05 AM »

Thanks Mike, I see that this model has animated bones where real women have none :). This animation must have been derived from an actor to render the full complexity of the human gait.

I'll need to 'bone-up' on the ModelView Matrix and how to manipulate it. Matrix multiplication always confuses me, so I just have to obediently follow the rules.

Frank, to associate mouse position with an object, we have the pick system implemented in OpenglSceneFrame. All you need to do is label the objects/components of interest with a number and, when the mouse clicks on the  labelled region, the number will be returned in picked

A more sophisticated use of picking is demonstrated in projectsA/Openglgui/viewer.o2bas, where picking is used in a text editor. It takes 3 passes to home in on a character pair to place the caret.