Clipping, and other 3D graphics questions.

Started by
1 comment, last by robertgamble 21 years, 2 months ago
Hi, I''m writing a simple 3D engine in &#106avascript and so far have it showing a cube, with backface culling. http://www.elephantsneverforget.co.uk/rg/3d%20engine/3dv1.htm w,a,s,d controls for moving around o,l looks up and down u,j moves up and down The big problem I have is when the cube is behind you it''s still visible, but reversed. Load up the url, and just walk straight forward until you go through the cube. Would this be because I need to implement frustrum clipping?? I know the idea behind it, but could really do with a good tutorial. So I''d really appreciate it if someone could point me in the right direction <img src="smile.gif" width=15 height=15 align=middle> If there''s perhaps a quicker way of doing clipping I''m open to suggestions <img src="smile.gif" width=15 height=15 align=middle> Also I''m doing backface culling by first transforming the polygon, then checking if it''s 2D coordinates are clockwise. Is there any way of doing this in 3D so that I wouldn''t have to transform polygons that wont ever be drawn? Thanks, Robert
Advertisement
To the last question the answer is yes. You can do it in 3D by taking the dot product of the eye-to-any-vertex vector with the face''s normal. A simple sign check will tell you if the polygon is facing the viewer or not.

Hi,

I've done this for my backface culling:

var visNml=new vector3D(objects.points[1].x-camera.x,objects.points[1].y-camera.y,objects.points[1].z-camera.z);<br>var vis=dot(objects.normal,visNml);<br><br>So I'm kind of drawing a line from my camera to a polygon face, and then getting the angle between that line and the polygon faces normal.<br><br><br>Which works great <img src="smile.gif" width=15 height=15 align=middle><br><br><br>I kind of know how to do the culling. I need 2 planes (for a start), left and right).<br><pre><br><br>\ /<br> \ /<br> x<br><br><br>[x] is my camera and the 2 lines and the planes. I then need to get the dot products:<br><br>dot(left_plain.normal,object.normal);<br>dot(right_plain.normal,object.normal);<br><br>and ensure that both dot products are higher than 0. Right??<br><br>I'm just not too sure of how to do this, particularly how to create these planes. <br><br>Any help would be greatly appreciated.<br><br><br><SPAN CLASS=editedby>[edited by - robertgamble &#111;n January 30, 2003 12:33:16 PM]</SPAN> </pre>

This topic is closed to new replies.

Advertisement