View Full Version : Finding location of a Polygon
03-15-2009, 10:55 AM
I am making a simple game however I am having problems with one bit of it. To do collision detection I need to know the location of the character however each time the game is played the character is placed in a random position (well not entirely random, there is an array for X positions and an array for Y positions). Because of this there is no set position to use so is there any way to find the location of a polygon? Like saving the X axis position of the middle of a corner of the polygon as a float?
03-15-2009, 11:44 AM
how do you generate the random position?
Isn't it possible to just store the generated random position?
If you stored everything like objects for example, you could have attributes to store the position of each actor and use that.
03-15-2009, 12:28 PM
I get the original value but it is the player controlled character and its position is changed by using gltranslatef(Xco, Yco, 1) where Xco and Yco are effected by the arrow keys. I tried recording its movement but the problem is Xco and Yco are set after I need to do collision detection.
03-15-2009, 01:16 PM
I tried recording its movement but the problem is Xco and Yco are set after I need to do collision detection.
Store the coordinates from the last keyboard callback call and use them in your collision function.
03-15-2009, 02:26 PM
I would again suggest you to make it object oriented. Or if you are using C for example, define a structure to store your character information such as position/orientation and stuff like health or whatever. It is more organized this way.
When your character move, set its new position inside the structure.
Then when to translate, read the position values from the character structure and translate it taking the identity as origin.
03-15-2009, 06:41 PM
When your making a game you should be running almost two separate applications (well really just one function after the other, but still).
the first one is the game and the other is the graphics.
The important thing is that openGL should not have anything to do with the game mechanics, it's just there to visually represent it.
Doing it that way you don't need to find out it's position, as you already know it.
03-16-2009, 04:22 AM
The problem is finding the original position. The characters original position is defined in a display list which means I can't return any values from it. The position updates correctly it is just the starting position I can't get. Also it is just a simple game (first one) so I am doing it all in OpenGL for the moment.
03-21-2009, 10:41 AM
you shouldn't be using displaylists.
Powered by vBulletin® Version 4.2.2 Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.