user3116196
user3116196

Reputation: 61

How to fully make 2d to 3d?

I'm using the method of dividing the x and y coordinates by the z value, then rendering it just like you would a 2D game/thing to create 3D looking thing. The problem is when the z value is less then 0 it flips the quadrants for the coordinate and looks very weird. At the moment there is only movement if someone could help me fix the negative z value thing and show me how to rotate. I'm not using and matrices only vectors that take in x,y and z for the maths if that helps. I'm making this using Java with no extra libraries. Thanks for the help.

I used the perspective matrix and multiplied it by my vector but it didn't work here is my code there might be something wrong with it. I just turned the vector into a 1 by 3 matrix and then did this.

    public Matrix multiply(Matrix matrix)
{
    Matrix result = new Matrix(getWidth(),getHeight());
    for(int y = 0; y < getHeight()-1; y++)
    {
        for(int x = 0; x < getWidth()-1; x++)
        {
            float sum = 0.0f;
            for(int e = 0; e < this.getWidth()-1; e++)
            {
                sum += this.matrix[e + y * getWidth()] * matrix.matrix[x + e * matrix.getWidth()];
            }
            result.matrix[x + y * getWidth()] = sum;
        }
    }
    return result;
} 

Upvotes: 1

Views: 91

Answers (1)

Solomon Slow
Solomon Slow

Reputation: 27115

Just guessing here, but it sounds like you are trying to do a projection transform: You are modeling 3D objects (things with X, Y, and Z coordinates) and you want to project them onto a 2D window (i.e., the screen).

The meaning of Z in the naive projection transform is the distance between the point and a plane parallel to the screen, that passes through your eyeball. If you have points with -Z, those represent points that are behind your head.

Sounds like you need to translate the Z coordinates so that Z=0 is the plane of the screen, or a plane parallel to and behind the screen. (In other words, Add a constant to all of your Zs, so that none of them is negative.)

http://en.wikipedia.org/wiki/3D_projection

Upvotes: 1

Related Questions