T_01
T_01

Reputation: 1359

3D projection doesnt work

Im trying to programm a 3D game with pure java, without any libraries like open gl (because i want to understand all the mathematics and techniches behind it). So, the first tests work very well, i can move around and rotate cubes and stuff like that, and i have a projection matrix to represent the camera of the world. But the this projection doesnt work correctly.

I can move the points around, but only about x and y, so right left, top bottom. but whenever i change the z coordinates of all points, nothing happens. The thing is my perspective projection isnt perspective at all. I can do everzthing, but points that are "far away" arent drawn "smaller"... why? Whats the problem?

Im working with matrices i already said, and use the following principe: every mesh has a list of lines, each line has to points, a point has the variables x, y, z, 1. So, whenever i want to transform all of these points i just multiply the needed transformation matrix (4x4) with each point matrix (4x1), and then the projection matrix with each point matrix, to get the new point matrix (4x1) of each point and drawing them again.

so i already said, the projection, (so the actual distance zoom) isnt working. why? Anyone an idea?

Thank you very much!

EDIT

okay, heres is some more information and code: Im using this projection matrix:

projectionmatrix

and here is some more code:

Camera.java

Graphics3D.java

BlockWorld.java That's the main programm, problem see line 48

Matrix.java

Upvotes: 2

Views: 966

Answers (2)

Daniel De León
Daniel De León

Reputation: 13639

Use Quaternion to make the projections. Thats save me once!

http://en.wikipedia.org/wiki/Quaternion

I use Commons Math: The Apache Commons Mathematics Library to make the maths, download the source code to check how it's work.

I have a sample here https://stackoverflow.com/a/16109249/980442

Upvotes: 0

Slihp
Slihp

Reputation: 793

You will need to transform your points using a perspective projection matrix rather than just a projection matrix to add depth

see

http://www.scratchapixel.com/lessons/3d-advanced-lessons/perspective-and-orthographic-projection-matrix/perspective-projection-matrix/

Upvotes: 2

Related Questions