# 3D scrolling

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

## Recommended Posts

Hi,

I develop a 3D shoot'em up with vertical scrolling. I want to know how to calculate the edges of the screen (the cone of vision?) to that my aircraft remains in the screen when the camera moves?

thx.

##### Share on other sites
you say cone of vision, but its more like a pyramid of vision (with the tip cut off (near plane)). If that's what you want, are you looking for the planes of vision? That's pretty easy to get. You just have to get your view*projection matrix, then get the six "frustum" planes (4 for the edges of the screen, 1 for near plane, and one for far plane):

// x,y,z,w represent the ABCD of the plane, where xyz (ABC) is the planes normal, while w (D) is the plane constant // you will need to use the view*projection matrix, then get the 4th column of the matrix, and either add or subtract // another column from it to get the desired plane (col[1] is the left and right planes, col[2] is the top and bottom // planes, and col[3] is the near and far planes) // Left Frustum Plane // Add first column of the matrix to the fourth column FrustumPlane[0].x = viewProj._14 + viewProj._11; FrustumPlane[0].y = viewProj._24 + viewProj._21; FrustumPlane[0].z = viewProj._34 + viewProj._31; FrustumPlane[0].w = viewProj._44 + viewProj._41; // Right Frustum Plane // Subtract first column of matrix from the fourth column FrustumPlane[1].x = viewProj._14 - viewProj._11; FrustumPlane[1].y = viewProj._24 - viewProj._21; FrustumPlane[1].z = viewProj._34 - viewProj._31; FrustumPlane[1].w = viewProj._44 - viewProj._41; // Top Frustum Plane // Subtract second column of matrix from the fourth column FrustumPlane[2].x = viewProj._14 - viewProj._12; FrustumPlane[2].y = viewProj._24 - viewProj._22; FrustumPlane[2].z = viewProj._34 - viewProj._32; FrustumPlane[2].w = viewProj._44 - viewProj._42; // Bottom Frustum Plane // Add second column of the matrix to the fourth column FrustumPlane[3].x = viewProj._14 + viewProj._12; FrustumPlane[3].y = viewProj._24 + viewProj._22; FrustumPlane[3].z = viewProj._34 + viewProj._32; FrustumPlane[3].w = viewProj._44 + viewProj._42; // Near Frustum Plane // We could add the third column to the fourth column to get the near plane, // but we don't have to do this because the third column IS the near plane FrustumPlane[4].x = viewProj._13; FrustumPlane[4].y = viewProj._23; FrustumPlane[4].z = viewProj._33; FrustumPlane[4].w = viewProj._43; // Far Frustum Plane // Subtract third column of matrix from the fourth column FrustumPlane[5].x = viewProj._14 - viewProj._13; FrustumPlane[5].y = viewProj._24 - viewProj._23; FrustumPlane[5].z = viewProj._34 - viewProj._33; FrustumPlane[5].w = viewProj._44 - viewProj._43;

These planes are not normalized, so you will have to normalize them:

 // For each of the six planes, do the following to normalize them float length = sqrt((FrustumPlane.x * FrustumPlane.x) + (FrustumPlane.y * FrustumPlane.y) + (FrustumPlane.z * FrustumPlane.z)); FrustumPlane.x /= length; FrustumPlane.y /= length; FrustumPlane.z /= length; FrustumPlane.w /= length;

These planes face INWARD, where their normals are pointing towards the center of the screen. You can test which side of a plane a point is on by getting the signed distance. if the signed distance is negative, then the point is on the outside of the screen, and if it's positive, you will have to check the other sides to see if it's actually in view. to get the signed distance between a plane and point:

signedDistance = planeNormal . point + planeConstant

Where planeNormal is the xyz (ABC) of the plane, and planeConstant is the w (D) of the plane

Thx!!

1. 1
2. 2
Rutin
19
3. 3
khawk
18
4. 4
A4L
14
5. 5

• 12
• 16
• 26
• 10
• 44
• ### Forum Statistics

• Total Topics
633766
• Total Posts
3013733
×