View Full Version : need some help with objects being placed in a C++ program
Blorx2
2005.05.02, 06:22 PM
How would you put a certain object in a ceratin place in a 2D C++ game? I'm sorry to bug you like this but I've read over the 2 books I have a few times and it says nothing of positioning...can someone help?
Puzzler183
2005.05.02, 07:16 PM
Well, every object problem has a 2D vector which gives the in game X and Y position. These are then converted to whatever the on screen X and Y pixel positions are based on what the viewport is. For example, if my object is at <20, 20> and the upperleft corner of the screen is at <10, 10>, then I would display the object at <20, 20> - <10, 10> = <10, 10>. That of course assume that the distance unit (which you pick, just make it appropriate) is the same as a pixel.
Blorx2
2005.05.02, 07:38 PM
Ok, thanks. I'll try it and see what happens. Any special command that I need to know?
Lindley
2005.05.02, 07:55 PM
A lot depends on what method you're using the draw the object on the screen.
kodex
2005.05.02, 07:59 PM
Please be more specfic
Are you using OpenGL? I assume yes
Are your using glOrtho? If so look into that
Using Ortho to set up your window as whatever size you want then use gltranslate to pass the position of the object. Fromt here you can scale, rotate, or move as desired.
Blorx2
2005.05.02, 08:28 PM
I'm using OpenGL of course. I just need to know the commands for scaling, resizing, positioning, etc.
Puzzler183
2005.05.02, 09:13 PM
glScalef, glTranslatef, glRotatef... Of course you would do your self a favor to learn some basic vector and matrix math so you could make the transformations yourself.
vBulletin® v3.6.8, Copyright ©2000-2008, Jelsoft Enterprises Ltd.