-
Camera (Wall Alpha-ing)
Hello everyone,
I've built a third person camera in C++ using DirectX that attaches itself to game objects such as the player. My walls are planes and I am utilizing line segment to plane intersection to know which walls I should alpha. The line segment is between my camera and the object I am attached to.
Here's the problem:
I can angle my camera to have a wall block half my view before rotating it enough for the line segment to plane intersection collision to detect that I am should alpha a certain wall.
Here's what I tried:
I get the magnitude of the point on the plane and the closest point on the line to the plane, subtract the two, and compare it to a distance to check wall alpha-ing.
Code:
vector3 vPtOnPlane = fPlaneOffset * vPlaneNormal;
vector3 a= vector3(vCameraPosition);
vector3 b= vector3(vTargetPosition);
vector3 line = b - a;
vector3 linePt = ClosestPtToPlane(vector3 start, vector3 end, vector3 ptOnePlane);
if( fabs(DotProduct(linePt, linePt) - DotProduct(vPtOnPlane, vPtOnPlane) < 50)
AlphaOutWall();
The code doesn't seem to work so I'm looking for alternative solutions.
-
Have a bounding box around your game object (you probably already have this if you're doing collision detection). Draw 8 lines from your camera to each corner of the bounding box, if any of those lines intersect a wall alpha that wall.
-
That sounds like it will work but also fairly expensive. I've consulted with my teacher and he told me to send collision information to the vertex shader and alpha out part of the wall in the fragment/pixel shader. Making the GPU do the work seems to be the optimal thing to do.
-
You're still going to have to determine which part of the wall intersects the view to the object (the collision information you're sending to the GPU). 8 tests of a line intersecting a plane will not have any noticeable performance effects. That's a rather simple computation.