34#include "d:/g/app/main/debug_o.h"
47 if((fabs(e1) > 0.001) || (fabs(e2) > 0.001) || (fabs(e3) > 0.001)) {
48 Debug.Print(
"----------\n");
62 if(!Verify_Normal(Normal, loc1,loc2,loc3)) {
64 if(Verify_Normal(normal, loc1,loc2,loc3)) {
65 Debug.Print(
"calculated worked.\n");
113 float xscale = (
max.X -
min.X);
114 float yscale = (
max.Y -
min.Y);
117 float xmod = (-
ScreenX + 0.5 + viewport.
Min.
X) * zmod * xscale;
118 float ymod = (
ScreenY - 0.5 - viewport.
Min.
Y) * zmod * yscale;
131 float x = zmod * camera_matrix[0][2] + xmod * camera_matrix[0][0] + ymod * camera_matrix[0][1];
132 float y = zmod * camera_matrix[1][2] + xmod * camera_matrix[1][0] + ymod * camera_matrix[1][1];
133 float z = zmod * camera_matrix[2][2] + xmod * camera_matrix[2][0] + ymod * camera_matrix[2][1];
170 bool intersect =
false;
177 if ((beta >= 0.0f) && (beta <= 1.0f)) {
178 alpha = (v0 - beta * v2) / v1;
183 intersect = ((alpha >= 0.0) && ((alpha + beta) <= 1.0));
186 beta = (v0 * u1 - u0 * v1) / (v2 * u1 - u2 * v1);
187 if ((beta >= 0.0) && (beta <= 1.0)) {
188 alpha = (u0 - beta * u2) / u1;
189 intersect = ((alpha >= 0.0) && ((alpha + beta) <= 1.0));
198 Point[
AXIS_3] = u3 * alpha + v3 * beta + Corner1[
AXIS_3];
231 double u0 = Point[axis_1] - loc1[axis_1];
232 double v0 = Point[axis_2] - loc1[axis_2];
235 double u1 = loc2[axis_1] - loc1[axis_1];
236 double v1 = loc2[axis_2] - loc1[axis_2];
237 double u2 = loc3[axis_1] - loc1[axis_1];
238 double v2 = loc3[axis_2] - loc1[axis_2];
241 bool intersect =
false;
247 bool debugmode =
false;
248 if(FinalResult->Alpha == 777) {
254 Beta = beta = u0 / u2;
255 if ((beta >= 0.0f) && (beta <= 1.0f)) {
256 Alpha = alpha = (v0 - beta * v2) / v1;
261 intersect = ((alpha >= 0.0) && ((alpha + beta) <= 1.0));
264 Beta = beta = (v0 * u1 - u0 * v1) / (v2 * u1 - u2 * v1);
265 if ((beta >= 0.0) && (beta <= 1.0)) {
266 Alpha = alpha = (u0 - beta * u2) / u1;
267 intersect = ((alpha >= 0.0) && ((alpha + beta) <= 1.0));
273 Debug.Print(
"Intersect", intersect);
274 Debug.Print(
"Normal ", Normal);
275 Debug.Print(
"Point 1", loc1);
276 Debug.Print(
"Point 2", loc2);
277 Debug.Print(
"Point 3", loc3);
278 Debug.Print(
"Inter ", FinalResult->Intersection);
279 Debug.Print(
"a/b", (
float) alpha, (
float) beta);
280 Debug.Print(
"sum", (
float) alpha + (
float) beta);
281 Debug.Print(
"diff", (
float) (alpha - beta));
312 axis_1, axis_2, FinalResult->
Alpha, FinalResult->
Beta));
335 float divisor = (PlaneNormal[0] *(*RayDirection)[0] + PlaneNormal[1] *(*RayDirection)[1] + PlaneNormal[2] * (*RayDirection)[2]);
336 if(divisor == 0)
return false;
339 double d = - (PlanePoint[0] * PlaneNormal[0] + PlanePoint[1] * PlaneNormal[1] + PlanePoint[2] * PlaneNormal[2]);
341 float value = - (d + PlaneNormal[0] * (*RayLocation)[0] + PlaneNormal[1] * (*RayLocation)[1] + PlaneNormal[2] * (*RayLocation)[2]) / divisor;
357 if(PlaneNormal[2] == 0)
return false;
360 double d = - (PlanePoint[0] * PlaneNormal[0] + PlanePoint[1] * PlaneNormal[1] + PlanePoint[2] * PlaneNormal[2]);
362 float value = - (d + PlaneNormal[0] * Point[0] + PlaneNormal[1] * Point[1] ) / PlaneNormal[2];
400 float divisor = (PlaneNormal[0] *(*RayDirection)[0] + PlaneNormal[1] *(*RayDirection)[1] + PlaneNormal[2] * (*RayDirection)[2]);
401 if(divisor == 0)
return false;
404 float d = - (PlanePoint[0] * PlaneNormal[0] + PlanePoint[1] * PlaneNormal[1] + PlanePoint[2] * PlaneNormal[2]);
405 Result->Range = - (d + PlaneNormal[0] * (*RayLocation)[0] + PlaneNormal[1] * (*RayLocation)[1] + PlaneNormal[2] * (*RayLocation)[2]) / divisor;
425 if(
Result->Range <= 0)
return false;
444 float x = fabsf(v[0]);
445 float y = fabsf(v[1]);
446 float z = fabsf(v[2]);
496 Verify_Normal2(PolygonNormal, v1,v2,v3);
515#ifdef ALLOW_TEMPORARIES
530#ifdef ALLOW_TEMPORARIES
556 Final_Result->
Range = 0;
796 float val = de.
X*dp.
Y - de.
Y*dp.
X;
811 float dpx = p1.
X - p0.
X;
812 float dpy = p1.
Y - p0.
Y;
814 float den = de.
Y * dpx - de.
X * dpy;
818 float num = p0.
Y*de.
X - p0.
X*de.
Y + e0.
X*de.
Y - e0.
Y*de.
X;
820 if ((t >= 0.0f) && (t <= 1.0f)) {
829#define EMIT(p,uv) OutPoints[outnum] = p; OutUVs[outnum] = uv; outnum++;
843 Vector3 de = edge_point1 - edge_point0;
858 for (p1=0; p1<incount; p1++) {
864 EMIT(InPoints[p1],InUVs[p1]);
870 intersection_point = (1.0f - intersection) * InPoints[p0] + intersection * InPoints[p1];
871 intersection_uv = (1.0f - intersection) * InUVs[p0] + intersection * InUVs[p1];
872 EMIT(intersection_point,intersection_uv);
873 EMIT(InPoints[p1],InUVs[p1]);
881 intersection_point = (1.0f - intersection) * InPoints[p0] + intersection * InPoints[p1];
882 intersection_uv = (1.0f - intersection) * InUVs[p0] + intersection * InUVs[p1];
883 EMIT(intersection_point,intersection_uv);
void Get_View_Plane(Vector2 &set_min, Vector2 &set_max) const
void Get_Viewport(Vector2 &set_min, Vector2 &set_max) const
float Get_Depth(void) const
Debug module main class (singleton).
bool Intersect_Plane(IntersectionResultClass *Result, Vector3 &Plane_Normal, Vector3 &Plane_Point)
IntersectionResultClass Result
void Transform_Model_To_World_Coords(IntersectionResultClass *FinalResult)
void Get_Screen_Ray(float ScreenX, float ScreenY, const LayerClass &Layer)
debug code that will be tossed
static float Intersect_Lines(const Vector3 &p0, const Vector3 &p1, const Vector3 &e0, const Vector3 &de)
Vector3 * IntersectionNormal
static bool In_Front_Of_Line(const Vector3 &p, const Vector3 &e0, const Vector3 &de)
float Plane_Z_Distance(Vector3 &PlaneNormal, Vector3 &PlanePoint)
static int Clip_Triangle_To_LineXY(int incount, Vector3 *InPoints, Vector2 *InUVs, Vector3 *OutPoints, Vector2 *OutUVs, const Vector3 &edge_point0, const Vector3 &edge_point1)
static void _Find_Polygon_Dominant_Plane(Vector3 &Normal, int &Axis_1, int &Axis_2)
bool Intersect_Plane_Quick(IntersectionResultClass *Result, Vector3 &Plane_Normal, Vector3 &Plane_Point)
static int _Intersect_Triangles_Z(Vector3 ClipPoints[3], Vector3 TrianglePoints[3], Vector2 UV[3], Vector3 ClippedPoints[6], Vector2 ClippedUV[6])
bool Intersect_Screen_Object(IntersectionResultClass *Final_Result, Vector4 &Area, RenderObjClass *obj=0)
static float _Get_Z_Elevation(Vector3 &Point, Vector3 &PlanePoint, Vector3 &PlaneNormal)
void Calculate_Intersection(IntersectionResultClass *Result)
static bool _Point_In_Polygon_Z(Vector3 &Point, Vector3 Corners[3])
bool Intersect_Polygon_Z(IntersectionResultClass *Result, Vector3 &PolygonNormal, Vector3 &v1, Vector3 &v2, Vector3 &v3)
static bool _Point_In_Polygon(IntersectionResultClass *FinalResult, Vector3 &Normal, Vector3 &loc1, Vector3 &loc2, Vector3 &loc3)
bool Intersect_Polygon(IntersectionResultClass *Result, Vector3 &PolygonNormal, Vector3 &v1, Vector3 &v2, Vector3 &v3)
static int _Largest_Normal_Index(Vector3 &v)
RenderObjClass * IntersectedRenderObject
enum IntersectionResultClass::INTERSECTION_TYPE IntersectionType
void mulVector3(const Vector3 &in, Vector3 &out) const
Vector3 Get_Position(void) const
const Matrix3D & Get_Transform(void) const
static WWINLINE float Dot_Product(const Vector3 &a, const Vector3 &b)
static WWINLINE void Cross_Product(const Vector3 &a, const Vector3 &b, Vector3 *result)