But before that I'd like to get Normal Maps etc working with Deferred Rendering..
![Image](http://i.imgur.com/stoRxp5.jpg)
Code: Select all
// Normal "should" be normalised. (especially if using Dot Product to determine on which side a checked point is located)
vector3df GetPlaneIntersectionGivenLineTwoEndPoints (vector3df LinePtA ,vector3df LinePtB , vector3df Pln, vector3df PNml)
{
vector3df ClosePtA;
vector3df ClosePtB;
ClosePtA.X = (LinePtA.X * (PNml.Y * PNml.Y) + LinePtA.X * (PNml.Z * PNml.Z) + (PNml.X * PNml.X) * Pln.X
- PNml.X * PNml.Y * LinePtA.Y + PNml.X * PNml.Y * Pln.Y
- PNml.X * PNml.Z * LinePtA.Z + PNml.X * PNml.Z * Pln.Z )
/ ((PNml.X * PNml.X) + (PNml.Y * PNml.Y) + (PNml.Z * PNml.Z));
ClosePtA.Y = (LinePtA.Y * (PNml.X * PNml.X) + LinePtA.Y * (PNml.Z * PNml.Z) - PNml.Y * PNml.X * LinePtA.X
+ PNml.Y * PNml.X * Pln.X + (PNml.Y * PNml.Y) * Pln.Y
- PNml.Y * PNml.Z * LinePtA.Z + PNml.Y * PNml.Z * Pln.Z)
/ ((PNml.X * PNml.X) + (PNml.Y * PNml.Y) + (PNml.Z * PNml.Z));
ClosePtA.Z = (LinePtA .Z * (PNml.X * PNml.X) + LinePtA.Z * (PNml.Y * PNml.Y)
- PNml.Z * PNml.X * LinePtA.X
+ PNml.Z * PNml.X * Pln.X - PNml.Z * PNml.Y * LinePtA.Y + PNml.Z * PNml.Y * Pln.Y + Pln.Z * (PNml.Z * PNml.Z))
/ ((PNml.X * PNml.X) + (PNml.Y * PNml.Y) + (PNml.Z * PNml.Z));
ClosePtB.X = (LinePtB.X * (PNml.Y * PNml.Y) + LinePtB.X * (PNml.Z * PNml.Z) + (PNml.X * PNml.X) * Pln.X
- PNml.X * PNml.Y * LinePtB.Y + PNml.X * PNml.Y * Pln.Y
- PNml.X * PNml.Z * LinePtB.Z + PNml.X * PNml.Z * Pln.Z )
/ ((PNml.X * PNml.X) + (PNml.Y * PNml.Y) + (PNml.Z * PNml.Z));
ClosePtB.Y = (LinePtB.Y * (PNml.X * PNml.X) + LinePtB.Y * (PNml.Z * PNml.Z) - PNml.Y * PNml.X * LinePtB.X
+ PNml.Y * PNml.X * Pln.X + (PNml.Y * PNml.Y) * Pln.Y
- PNml.Y * PNml.Z * LinePtB.Z + PNml.Y * PNml.Z * Pln.Z)
/ ((PNml.X * PNml.X) + (PNml.Y * PNml.Y) + (PNml.Z * PNml.Z));
ClosePtB.Z = (LinePtB.Z * (PNml.X * PNml.X) + LinePtB.Z * (PNml.Y * PNml.Y)
- PNml.Z * PNml.X * LinePtB.X
+ PNml.Z * PNml.X * Pln.X - PNml.Z * PNml.Y * LinePtB.Y + PNml.Z * PNml.Y * Pln.Y + Pln.Z * (PNml.Z * PNml.Z))
/ ((PNml.X * PNml.X) + (PNml.Y * PNml.Y) + (PNml.Z * PNml.Z));
vector3df DeltaCloseA;
vector3df DeltaCloseB;
// I know that there are operators for these that would cost less code,
// but when converting to Inline Assembly (maybe some time) this would be easier to read and translate..
DeltaCloseA.X = ClosePtA.X - LinePtA.X;
DeltaCloseA.Y = ClosePtA.Y - LinePtA.Y;
DeltaCloseA.Z = ClosePtA.Z - LinePtA.Z;
DeltaCloseB.X = ClosePtB.X - LinePtB.X;
DeltaCloseB.Y = ClosePtB.Y - LinePtB.Y;
DeltaCloseB.Z = ClosePtB.Z - LinePtB.Z;
f32 DistA = sqrt ((DeltaCloseA .X * DeltaCloseA.X)
+(DeltaCloseA .Y * DeltaCloseA.Y)
+(DeltaCloseA .Z * DeltaCloseA.Z));
f32 DistB = sqrt ((DeltaCloseB.X * DeltaCloseB.X)
+(DeltaCloseB.Y * DeltaCloseB.Y)
+(DeltaCloseB.Z * DeltaCloseB.Z));
f32 Relation = DistA / (DistA + DistB);
vector3df IntersectionPoint;
IntersectionPoint.X = ClosePtA.X + ((ClosePtB.X - ClosePtA.X) * Relation);
IntersectionPoint.Y = ClosePtA.Y + ((ClosePtB.Y - ClosePtA.Y) * Relation);
IntersectionPoint.Z = ClosePtA.Z + ((ClosePtB.Z - ClosePtA.Z) * Relation);
return IntersectionPoint;
}
Code: Select all
#define NO_INTERSECTION 0
#define INTERSECTION_FOUND 1
#define PARALLEL_TO_PLANE_AND_ON_PLANE 2 // (a little extra)
float GetDotProduct (vector3df VecA, vector3df VecB)
{return (VecA.X * VecB.X) + (VecA.Y * VecB.Y) + (VecA.Z * VecB.Z);
}
vector3df AcquiredIntersection; // This is what it's all about..
struct Segment // Finite Line with a Start and an End..
{vector3df P0; // Line Start..
vector3df P1; // Line End..
};
struct Plane
{vector3df Normal; // Plane Direction..
vector3df V0; // Any Position on the Plane..
};
Code: Select all
int GetSegmentAndPlaneIntersection(Segment TheSegment, Plane ThePlane, vector3df* Intersection)
{vector3df SegVect = TheSegment.P1 - TheSegment.P0;
vector3df SegMinPlaneVect = TheSegment.P0 - ThePlane.V0;
float DotProduct = GetDotProduct(ThePlane.Normal, SegVect);
float NegDot = -GetDotProduct(ThePlane.Normal, SegMinPlaneVect);
if (fabs(DotProduct) < 0.00001) // How stringent is the rules applied?
{if (NegDot == 0.0) return PARALLEL_TO_PLANE_AND_ON_PLANE;
else
return NO_INTERSECTION;
}
float sI = NegDot / DotProduct;
if (sI < 0 || sI > 1) return NO_INTERSECTION;
*Intersection = TheSegment.P0 + sI * SegVect;
return INTERSECTION_FOUND;
}
Code: Select all
// Where "Situation" could be one of three things as #defined at the top..
// and "AcquiredIntersection" is passed by reference (and possibly loaded when there is an intersection)..
int Situation = GetSegmentAndPlaneIntersection(MyLineSegment, MyPlane, &AcquiredIntersection);