I've been getting into crafting my own 3D-engine in Java (mostly for kicks, but also I like to have full control over everything I use).
It's been going great for the most part (haven't gotten far), and I can now draw wireframes almost perfectly.
The formula I use for calculating where to draw a point on the screen is:
zDifference = abs(z - camera.z); screenX = camera.lens * (x - camera.x) / zDifference); screenY = camera.lens * (y - camera.y) / zDifference);
This works just fine, except for one thing.
When the point goes back behind the camera, it completely stops working.
Ok, so obviously I shouldn't draw a point behind the camera, right? Problem solved? Well, almost...
Image a line, drawn between two points. Imagine walking past the first one, but the second one still being visible. When this happens, the line goes haywire, since the calculations for the first point stop working. So I can't just "not draw the point", since I need it to draw the complete line. I still need to calculate where on the screen (it will be off-screen, but still) this point should be drawn, so I can after that draw a line between the two.
You can check out and see the issue in-action here.
So, how should I go about fixing this? Is the formula completely stupid, or should I find a way to work around this issue?
Any response is greatly appreciated
Have a good one,
Edited by Vrokulaf, 17 February 2013 - 10:53 AM.