Getting the Size of objects
Hi guys!!
I would like to know how I could get the Size of Objects in OpenGL, independent of my Z-axis position.
I''m making a application, where I have a mouse, and when I click on the screen, the application have to search for objects and select them, if the the click were under any.
The problem is that the object can be in any position (in Z-axis), and I have to make a calculus if its Z axis were different of 0.
If anyone could pass me the calculus or some tips to do that, I''ll be extremelly glad!
Thank you guys!
Do you want to use the size of the objects to help you select the object under the mouse cursor ?
Or you want to select an object under the mouse cursor, and then comput the size of this object to compute stuff about this size ?
Anyway, to get the object under a mouse cursor, I suggest picking (which uses selction buffer).
Take a look at OpenGL Red Book (gamedev.net->articles & resources->OpenGL->Online books), in Chapter 13 "Selection and Feedback". There are very good explanations on how picking works and there is an example of code for using it.
btw, picking needs the GLU.
Or you want to select an object under the mouse cursor, and then comput the size of this object to compute stuff about this size ?
Anyway, to get the object under a mouse cursor, I suggest picking (which uses selction buffer).
Take a look at OpenGL Red Book (gamedev.net->articles & resources->OpenGL->Online books), in Chapter 13 "Selection and Feedback". There are very good explanations on how picking works and there is an example of code for using it.
btw, picking needs the GLU.
I Want to know the size of the Object in PIXELS!
For Example.
Let''s say that I have (it''s only a example) a object that has size of 2.0f in X, Y, Z. If it''s in position 0, 0, 0, the object will appear to be bigger than the object that is in 0, 0, -3.
I would like to know, How I could get the size of the objects in this condition! :-)
I Know that it have 2.0 in X, Y, Z, but what I want to know is the size in PIXELS!!!!!!!!!!!!!
Thank you again guys!
For Example.
Let''s say that I have (it''s only a example) a object that has size of 2.0f in X, Y, Z. If it''s in position 0, 0, 0, the object will appear to be bigger than the object that is in 0, 0, -3.
I would like to know, How I could get the size of the objects in this condition! :-)
I Know that it have 2.0 in X, Y, Z, but what I want to know is the size in PIXELS!!!!!!!!!!!!!
Thank you again guys!
the only way would be to draw the object in a colour say red and provided nothing else is red in the scene do a readpixels + count the number of red pixels (u could also use stencil) u might wanna turn depth testing off before u draw the object.
this is the ONLY way to get the exact size of the object on the screen
http://uk.geocities.com/sloppyturds/gotterdammerung.html
this is the ONLY way to get the exact size of the object on the screen
http://uk.geocities.com/sloppyturds/gotterdammerung.html
Ok zedzeek...
but isn''t there a calculus, for example:
for each negative unit the object walk back, the object will have a size in pixels of -0.2...
Isn''t there a calculus that I could do something like that?
but isn''t there a calculus, for example:
for each negative unit the object walk back, the object will have a size in pixels of -0.2...
Isn''t there a calculus that I could do something like that?
There is one other method you could use to determine size in pixels. You can use the call gluProject to get 2D coordinates from a 3d object if you call it for every vertex in your object. You could then see what the lowest screen x value is and what the greatest is, thus giving you the width. This can be done for the height as well. If you don''t want to call it for every vertex, you could loop through your vertices and check for greatest x, y, or z values if you know the object is facing a fixed direction and then you can pass the positions of the four vertices you isolated in gluProject to get the equivalent screen coordinates. This wouldn''t work if the 3d object is constantly being rotated.
Thank you cardinals333!!! :-)
I took a look at Blue Book, and I thing it''ll solve my problem!!!!
I''ll try to use this command, and after, post a message in this forum !!!!!
cya!!!
I took a look at Blue Book, and I thing it''ll solve my problem!!!!
I''ll try to use this command, and after, post a message in this forum !!!!!
cya!!!
Cardinals33''s solution works, but it''s very slow.
I suggest using the feedback buffer which gives faster results IMO.
Though, do you want the "size" of the objects to be clipped when the object is clipped to the viewing frustum ?
If you want only the size of the "visible" part of the object, then you should use the feedback buffer. Otherwise you should use gluProject.
And if you want the exact size of the object, you have to compute something more complex than a bouding rectangle.
I suggest using the feedback buffer which gives faster results IMO.
Though, do you want the "size" of the objects to be clipped when the object is clipped to the viewing frustum ?
If you want only the size of the "visible" part of the object, then you should use the feedback buffer. Otherwise you should use gluProject.
And if you want the exact size of the object, you have to compute something more complex than a bouding rectangle.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement