My crappy 3D graphics routine

Started by
4 comments, last by jho 22 years, 9 months ago
Hi, I just realized my 3D routine sucks, I know it can be simplified, but I have no idea how right now. My engine will render an array of 3Dlines (world space) in perspective mode. A 3Dline is just 2 3D points. Currently, for each frame, you specify the camera pos, camera look at pos, and view up vector (like GLULookAt). This is enough info to construct a Rotational matrix to transform world space to camera space. (as if the camera is in origin, looking at 0,0,Z) for a frame, it first go thru every 3D line in the array, multiply every point by the rotational matrix and then if a point is behind Z = 0. Then it discards it. Otherwise, it will do a perspective transform to 2D, and clip in 2D. My question is, there must be a way to get rid of many many lines IN WORLD SPACE given a camera lookat information.. So I don''t have to multiply each and every point by rotational matrix as the first step. Here is how I construct my rotational matrix with the camera position info: void camera:er_LookAt(const double posX, const double posY, const double posZ, const double lookX, const double lookY, const double lookZ, const double vupX, const double vupY, const double vupZ) { pos.set(posX, posY, posZ); lookat.set(lookX, lookY, lookZ); yAxis.set(vupX, vupY, vupZ); lookat.sub(pos,zAxis); //derive Z axis (view vector) by lookat-position zAxis.normalize(); zAxis.crossproduct(yAxis, xAxis); //get X axis of the camera xAxis.normalize(); xAxis.crossproduct(zAxis, yAxis); //fix Y axis again yAxis.normalize(); R_matrix.element[0][0] = xAxis.x; R_matrix.element[0][1] = xAxis.y; R_matrix.element[0][2] = xAxis.z; R_matrix.element[0][3] = -pos.dot(xAxis); R_matrix.element[1][0] = yAxis.x; R_matrix.element[1][1] = yAxis.y; R_matrix.element[1][2] = yAxis.z; R_matrix.element[1][3] = -pos.dot(yAxis); R_matrix.element[2][0] = zAxis.x; R_matrix.element[2][1] = zAxis.y; R_matrix.element[2][2] = zAxis.z; R_matrix.element[2][3] = -pos.dot(zAxis); R_matrix.element[3][0] = 0.0f; R_matrix.element[3][1] = 0.0f; R_matrix.element[3][2] = 0.0f; R_matrix.element[3][3] = 1.0f; }
Advertisement
Hmmm... Well one way is to cull your lines using frustum culling. In frustum culling you take the 6 planes that make up your view frustum (left, right, top, bottom, near and far) and test your lines against them. If both points of your line are on the outside of the same plane you can discard the line entirely, otherwise draw it entirely or clip it after it is 2D.

Now you are saying (but I still have to rotate my points!!). Not so. Now you can rotate your frustum planes and check each point against the rotated planes. It takes a little tweaking to get right but it''s not too bad

Then if that is not fast enough and you have alot of lines, you can group your lines in boxes of world-space, and instead of checking each line, you check the box that contains that line and if the box is not visible, none of the lines inside of the box are visible either.

Here is a link that I found very useful:

Right Here!


Seeya
Krippy
Thanks let me think about it,,

would Quadtrees work?


Edited by - jho on June 25, 2001 10:57:44 PM
Well I have never actually learned much about quadtrees. But from what I have heard (which is not much) they are basically a 2D version of an octree. I know that an octree works great and it is what I use. But I think some people prefer to use quadtrees. Not sure what the reason would be. I imagine you can do some kind of projection calculations to group your lines in 2D quads or something but that sounds kinda expensive to me since I don''t think it could be static? lol

Maybe I should just go to bed now...

Seeya
Krippy
QuadTrees are useful in 3D for basically 2D applications. Terrain Rendering is probably the best example. You only need to cull based on 2D data, so there is no reason for an OctTree.

Z.
______________"Evil is Loud"
Do you guys know how to find out the side planes of the viewing frustum? I am trying to clip them against my lines.

So far I only have the back plane of the camera.

This topic is closed to new replies.

Advertisement