PDA

View Full Version : How to view object in centre



vicks47
02-20-2003, 09:38 AM
Hi,
I am pretty new to OpenGl and facing some basic difficulties.
I am visualizing some VRML files in openGL. These files are of some objects with different coordinates and connectivities. Everytime I render, I have to do some manual translation and scaling to get the object in the view window.Is there any way or any function in OpenGL, which can automatically render the object in the centre of the window everytime I render ?
Thanks in anticipation !

shinpaughp
02-20-2003, 10:38 AM
Depends... What is the range of coordinates relative to each axis? How do you have projection set up (i.e. glOrtho, glFrustum, gluProjection)? There isn't a centering function in OpenGL. You should be able to change parameters of projection functions to get better results. Dependent on how big objects are, and where their coordinates place them initially. If the entire object is initially located far from center (0, 0, 0) then you could also adjust your entire set of vertices to be moved closer to center.

nexusone
02-20-2003, 12:08 PM
How about when you load the VRML file, parse it to get the center, hight, width and relative location of the object.

Once you know that you can have your program automaticaly set the scale, rotate, translate to put it in view.


Originally posted by vicks47:
Hi,
I am pretty new to OpenGl and facing some basic difficulties.
I am visualizing some VRML files in openGL. These files are of some objects with different coordinates and connectivities. Everytime I render, I have to do some manual translation and scaling to get the object in the view window.Is there any way or any function in OpenGL, which can automatically render the object in the centre of the window everytime I render ?
Thanks in anticipation !

marcus256
02-20-2003, 12:18 PM
nexusone's suggestion is probably what you need. For a more thorough discussion, see this post: http://www.opengl.org/discussion_boards/ubb/Forum4/HTML/000870.html

The post is actually about z buffer precision of an MDL model viewer, but it deals with the exact same topic (camera management and placement of the model). You can even find a link to the source if you look hard in the >50 messages http://www.opengl.org/discussion_boards/ubb/wink.gif

vicks47
02-20-2003, 01:45 PM
Thanks for the promt reply. But, the problem is, as I told u that I have several files in which the coordinates are different for each object. (I am using 'Projection'). Hence, I have to change the scale and translation parameters everytime, for different objects. Is there a way that everytime I view my object, its in the center of the window.
Thanks again !!!

Originally posted by shinpaughp:
Depends... What is the range of coordinates relative to each axis? How do you have projection set up (i.e. glOrtho, glFrustum, gluProjection)? There isn't a centering function in OpenGL. You should be able to change parameters of projection functions to get better results. Dependent on how big objects are, and where their coordinates place them initially. If the entire object is initially located far from center (0, 0, 0) then you could also adjust your entire set of vertices to be moved closer to center.

nexusone
02-20-2003, 03:06 PM
Repeating your question will not make the answer we have giving you any diffrent.

Maybe you should study more on how openGL and the project works in relation to objects.

nehe.gamedev.net has some good tutors to help you in learning opengl.


Originally posted by vicks47:
Thanks for the promt reply. But, the problem is, as I told u that I have several files in which the coordinates are different for each object. (I am using 'Projection'). Hence, I have to change the scale and translation parameters everytime, for different objects. Is there a way that everytime I view my object, its in the center of the window.
Thanks again !!!

vicks47
02-20-2003, 04:45 PM
Well, I thought reframing the question in a better way would help me in getting a better answer to my doubt. But, it seems u look for OpenGL pro in the beginners forum too.
Thanks anyways.

Originally posted by nexusone:
Repeating your question will not make the answer we have giving you any diffrent.

Maybe you should study more on how openGL and the project works in relation to objects.

nehe.gamedev.net has some good tutors to help you in learning opengl.

nexusone
02-21-2003, 05:11 AM
This is a beginners forum, the idea of a forum is to give you guidence as to how to achive your goal in programming a openGL program.
What you may not get is someone to do all the work for you.

That is why it is important you learn openGL basics by working with the openGL tutors on a site like nehe.gamedev.net
You are not going to write a quake V the first time you program.

Once you have gone through some of the tutors, you will better understand some of the answer you will get as a solution.

Since you did not understand my answer, since there is no code I have to parse your model for the information one would have to be wretten.
Parse means to look over something to get a over view of the data.

1. Learn about how your model loading routine works and the format of the data of the model.
2. Once you know that, you can write a routine to get the information on the center, hight and width of the object as it is loaded.

Again we are happy to help, but you also have to put out some effort also in learning.



Originally posted by vicks47:
Well, I thought reframing the question in a better way would help me in getting a better answer to my doubt. But, it seems u look for OpenGL pro in the beginners forum too.
Thanks anyways.