• ### Announcements

#### Archived

This topic is now archived and is closed to further replies.

# Clipping, and other 3D graphics questions.

## Recommended Posts

Hi, I''m writing a simple 3D engine in javascript 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 If there''s perhaps a quicker way of doing clipping I''m open to suggestions 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

##### Share on other sites
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.

##### Share on other sites
Hi,

I've done this for my backface culling:

var visNml=new vector3D(objects[ i ].points[1].x-camera.x,objects[ i ].points[1].y-camera.y,objects[ i ].points[1].z-camera.z);
var vis=dot(objects[ i ].normal,visNml);

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.

Which works great

I kind of know how to do the culling. I need 2 planes (for a start), left and right).
\   / \ /  x[code][x] is my camera and the 2 lines and the planes.  I then need to get the dot products:dot(left_plain.normal,object.normal);dot(right_plain.normal,object.normal);and ensure that both dot products are higher than 0.  Right??I'm just not too sure of how to do this, particularly how to create these planes. Any help would be greatly appreciated.[edited by - robertgamble on January 30, 2003 12:33:16 PM]

• ### Forum Statistics

• Total Topics
627708
• Total Posts
2978732

• 21
• 14
• 12
• 22
• 35