Jump to content
  • Advertisement
Sign in to follow this  

OpenGL object placement/location

This topic is 4081 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey guys, I'm fairly new to OGL and didn't know whether to post this in this forum or the OGL but I figured it would get more exposure here. I am currently working on getting a basic billiards up and running but I am having some issues with understanding how to place objects in OpenGL when working in a 3D space. I've worked in 2D space before and done some stuff including making a heirarchy moveable robot and also making a sodoku game, but the part I found easy was the fact that I was doing everything in 2D, so 1 pixel was 1 pixel. When I wanted to place a square at the center of the screen, I knew the window size and knew exactly how big to make the quad at the center because there was no depth. Now I've come to 3-space and I'm confused as to how to place things. I've read through some of the NeHe tutorials, but they give lessons on how to do things, not an explanation as to how to place them, etc. So I know I need to get the following drawn: - 16 balls - a table - a cue - maybe some other stuff (power meter? ball spin thingy?) But how do I know where in 3 space to put these things for them to match my phyiscal game? This is how I setup my 3D Space:
void cRender::Set3DView()
	int origin = 0;
	int width = gWinManager->GetWidth();
	int height = gWinManager->GetHeight();

	glViewport(0, 0, width, height);


	// Calculate the aspect ratio of the window
	gluPerspective(45.0f, static_cast<float>(width)/static_cast<float>(height), 1.0f, 100.0f);


Where width is 640, and height is 480. Now I know the concept behind the viewing frustum and how that works. Let's say I pick dimensions for my billiards table to be 4' by 8' and I pick a diameter of my ball to be 2.25". Now I need to fit the table into my 640x480 window and be able to place all the balls on the table. Let's say for example that I want to use a green quad to show my table top. How exactly do I know what size to make my quad? and more importantly, how do I know what Z depth to use to place it? Can I can some sort of a co-ordinate system? Do I just have to keep trying different Z depths until I find one that lets me fit it on to the screen? There must be a more efficient way of doing this... Or at least I would hope so. Some sort of a way with a pen and paper to plan out all my renderings instead of trial and error. I hope my question makes sense. I know it is a really broad topic, but I'm sure there is some sort of a link someone can point out that covers this topic? I've found that most tutorials just show you how to do specific things without explaining how they're done. Oh, and moreso. I need to be able to make the balls in my physical simulation obviously match up with those that are being rendered. So if I pick a co-ordinate system for my balls, how do I make them match up with the OGL rendering world? So if I know that the limits of my billiards table is something like -2, +2 on the X axis and -4, +4 on the Y axis and I make the balls work within those bounds how do I translate that to the OGL world? Do I have to find a Z-depth where those values work for my ball and my table size? Thanks in advance and sorry for the long and possibly confusing post. :) Sim

Share this post

Link to post
Share on other sites

First: instead of creating the models you use in your program, you create them in an external application. You then import these models into your application, and display them. This helps with getting the relative scale of objects right.

Second: you don't really have to worry about screen coordinates. Just place everything right in 3D space, implement a movable camera and find the view you're looking for with it. If later on you don't want the camera to move, just display it's current coordinates and orientation and hardcode them into your app.

Matching up your physical objects with OpenGL is trivial: you don't need two coordinate systems. OpenGL uses an orthogonal isometric coordinate system, which should suit your needs perfectly.

Share this post

Link to post
Share on other sites
From OpenGL.ort FAQs:

9.010 What are OpenGL coordinate units?

The short answer: Anything you want them to be.

Depending on the contents of your geometry database, it may be convenient for your application to treat one OpenGL coordinate unit as being equal to one millimeter or one parsec or anything in between (or larger or smaller).

OpenGL also lets you specify your geometry with coordinates of differing values. For example, you may find it convenient to model an airplane's controls in centimeters, its fuselage in meters, and a world to fly around in kilometers. OpenGL's ModelView matrix can then scale these different coordinate systems into the same eye coordinate space.

It's the application's responsibility to ensure that the Projection and ModelView matrices are constructed to provide an image that keeps the viewer at an appropriate distance, with an appropriate field of view, and keeps the zNear and zFar clipping planes at an appropriate range. An application that displays molecules in micron scale, for example, would probably not want to place the viewer at a distance of 10 feet with a 60 degree field of view.

So like Morrandir said, just draw your objects to scale in relation to one another, then move your camera to include what objects you want on your screen.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!