Hi all
I’m just having some issues understanding exactly where I might be going wrong in terms of implementing a 3D layer into my game (to function as a parallax). It’s top-down, and I figured that pseudo-3d would achieve the effect (things further away appear to move slower, etc…) but I have some issues with the way it appears.
I’ll outline what I’m trying to achieve - a top-down camera perspective on any number of projectable objects. In terms of positioning them in the world, and projecting them at correct positions, that works well. What I’m having trouble with is that when I try to represent these objects, they become warped depending on my position, and while I can see why that may be happening, I’m unable to understand how exactly to fix it.
Here’s my code for projecting a 3d point into 2d:
public int getProjectedX(float offset){
float camDist = Game.getCamera().perspectiveZ - z;
float camX = Game.getCamera().perspectiveX / pixelsPerMetre;
return (int) ((-(x + offset - (camX)) * (camDist / z) + camX) * pixelsPerMetre);
}
public int getProjectedY(float offset){
float camDist = Game.getCamera().perspectiveZ - z;
float camY = Game.getCamera().perspectiveY / pixelsPerMetre;
return (int) ((-(y + offset - (camY)) * (camDist / z) + camY) * pixelsPerMetre);
}
pixelsPerMetre is an integer equal to 64, and the camera’s perspectiveX is 1.
Offset is used when I render these objects so that I can calculate an object’s position, plus its width.
rendering is done by calling these methods. basically, i cannot understand why my view of these objects appears warped (maybe my maths is wrong - wouldn’t be the first time :P). I have read around that I may require a matrix, but I don’t see why - the camera perspective will remain the same, it will only move.
Any help would be appreciated.