PDA

View Full Version : too many transformations


hyperutila
2005.07.11, 07:58 PM
I am working on a 3D game which uses pathfinding to move an enemy toward the player. I have everything figured out fine in my head, except that there are a couple of problems when I put it in code. First, I have a level model that I load in which puts in walls and floors and such. Without transformations, the level is rotated 90 degrees around the x axis and is 1/5 the size that I would like it to be. So, the whole level is vertical instead of flat, which is fine, because all I need to do is apply a couple opengl transformations to rotate it and scale it and then everything looks fine. But then my problem comes when I run collision detection on it. You see, my camera location is based on the rotated and scaled version, not on the actual data that has been loaded in for the model. So, I have to divide the camera's coordinates by 5 and swap the z and y coordinates in order to get a coordinate relative to the walls that I can then perform the collision detection with. So, after a bit of trial and error, I got that to work fine, but then I decided that I wanted to use the same collision detection function to determine a path for the enemies to move to the camera position through the level. I loaded in the vertecies for the initial positioning of the enemies from another file that also required a similar scaling and rotation in order to be correct, relative to the camera. So now, I have each of these enemy locations loaded in correctly, in relation to the camera location, but incorrectly, in relation to the level, since I simply rely on an opengl transformation matrix to take care of scaling and rotating the level for me. So basically, when I try to check collision detection for the enemies, the transformations make everything totally messed up and overly complicated and I can't think straight anymore. Does anyone have an idea of how I can simplify this process?

OneSadCookie
2005.07.11, 08:02 PM
change the scale and orientation of the model to be correct, so you don't have to do any hackery?

PowerMacX
2005.07.11, 10:03 PM
Without transformations, the level is rotated 90 degrees around the x axis and is 1/5 the size that I would like it to be. So, the whole level is vertical instead of flat, which is fine, because all I need to do is apply a couple opengl transformations to rotate it and scale it and then everything looks fine. But then my problem comes when I run collision detection on it. You see, my camera location is based on the rotated and scaled version, not on the actual data that has been loaded in for the model. So, I have to divide the camera's coordinates by 5 and swap the z and y coordinates in order to get a coordinate relative to the walls that I can then perform the collision detection with. So, after a bit of trial and error, I got that to work fine, but [...] basically, when I try to check collision detection for the enemies, the transformations make everything totally messed up and overly complicated and I can't think straight anymore. Does anyone have an idea of how I can simplify this process?

I made the exact same mistake with a game I made last year (Okugai (http://www.wirelesshamster.com/downloads.html)). I got it to work by much trial & error, swapping y / z, scaling, rotations, etc.

My advice: follow OneSadCookie's advice (above) ;)

hyperutila
2005.07.11, 11:18 PM
Aww, but that means that I have to go through and change all of my code. But yeah, now that I think about it, I have no idea why I didn't do it like that in the first place. That would have made everything waaay easier! Thanks!