#### Archived

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

# camera class & Frustum

This topic is 5374 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

well.. I''m working on my own 3D Engine... now it is time to create my Camera class and a view Frustum.. so I can remove stuff that isn''t visible.. well.. all tutorials I have seen so far is only OpenGL specefic code.. I want some API independent version. can I some way use the fov,zNear,zFar,aspect ratio (insert what I need here). to calculate a view Frustum? and how is it done? In theory I guess I could use the position of the camera and a forward direction vector, and a zNear value to define the Near plane and a zFar value to define a Far plane and a FOV to determine the top,bottom,left,right planes. to calculate the Near and Far plane it would be something like this I guess NearPlane.pos = Camera.pos + cVertex3f(0,0,zNear) * Camera.Forward; FarPlane.pos = Camera.pos + cVertex3f(0,0,zFar) * Camera.Forward; I havn''t tried though so I don''t know if this is right..

##### Share on other sites
*confused*
for most purposes you just need the position and direction/normal. so see if a point is inside, calculate the distance to the plane thats going through the camera position and has forward as normal:
dot(point-cam.position, forward)
compare with near and far.
for the other directions you can simply use the right and up vectors. also, as the the sides are not parallel you need to know a factor. for up/down thats tan(fov/2) (ie. half the height of the frustum for z=1) and for left/right its aspect*tan(fov/2). multiply with the first result to get the "limit" in each direction.

for spheres its either a little more complicated or losing some precision (basically testing the cube around the sphere rather than the sphere).

then theres always the "old fasioned" way of extracting the frustum plane normals.

##### Share on other sites
Im guessing that one of the tutorials is from GameTutorials.com? If it is, its extremly easy to convert it to DirectX. All the tutorial does is use the persective and view matrix in the form of a 16 float array. To get the array from a D3DXMatrix just do:
_matrix16[0] = yourMatrix._11;_matrix16[1] = yourMatrix._12;_matrix16[2] = yourMatrix._13;_matrix16[3] = yourMatrix._14;_matrix16[4] = yourMatrix._21;_matrix16[5] = yourMatrix._22;_matrix16[6] = yourMatrix._23;_matrix16[7] = yourMatrix._24;_matrix16[8] = yourMatrix._31;_matrix16[9] = yourMatrix._32;_matrix16[10] = yourMatrix._33;_matrix16[11] = yourMatrix._34;_matrix16[12] = yourMatrix._41;_matrix16[13] = yourMatrix._42;_matrix16[14] = yourMatrix._43;_matrix16[15] = yourMatrix._44;

Or you could just alter the code to take the D3DMatrix structure into account rather than use a 16 float array.

Spree

[edited by - SpreeTree on March 26, 2004 9:27:27 AM]

##### Share on other sites
It should be pretty easy (though I haven''t tried it).

top, bottom, left and right planes: Given the FOV and aspect ratio, you can compute the normals. You have a point on the planes (the camera''s position). That is enough information to compute these planes.

near and far planes: you have the normal (opposite of the camera''s direction) and the distances from a point (the camera''s position) to the planes. That is enough information to compute these planes.

1. 1
2. 2
Rutin
16
3. 3
4. 4
5. 5

• 26
• 11
• 9
• 9
• 11
• ### Forum Statistics

• Total Topics
633704
• Total Posts
3013460
×