Go to the documentation of this file.00001
00002
00008
00009
00011
00045
00046
00048
00049 #include "Stdafx.h"
00050
00051 using namespace IceMaths;
00052
00054
00058
00059 Point& Point::PositiveUnitRandomVector()
00060 {
00061 x = UnitRandomFloat();
00062 y = UnitRandomFloat();
00063 z = UnitRandomFloat();
00064 Normalize();
00065 return *this;
00066 }
00067
00069
00073
00074 Point& Point::UnitRandomVector()
00075 {
00076 x = UnitRandomFloat() - 0.5f;
00077 y = UnitRandomFloat() - 0.5f;
00078 z = UnitRandomFloat() - 0.5f;
00079 Normalize();
00080 return *this;
00081 }
00082
00083
00084
00085 Point::operator HPoint() const { return HPoint(x, y, z, 0.0f); }
00086
00087 Point& Point::Refract(const Point& eye, const Point& n, float refractindex, Point& refracted)
00088 {
00089
00090
00091
00092
00093
00094 Point Env;
00095 Env.x = eye.x - x;
00096 Env.y = eye.y - y;
00097 Env.z = eye.z - z;
00098
00099 float NDotE = n|Env;
00100 float NDotN = n|n;
00101 NDotE /= refractindex;
00102
00103
00104 refracted = n*NDotE - Env*NDotN;
00105
00106 return *this;
00107 }
00108
00109 Point& Point::ProjectToPlane(const Plane& p)
00110 {
00111 *this-= (p.d + (*this|p.n))*p.n;
00112 return *this;
00113 }
00114
00115 void Point::ProjectToScreen(float halfrenderwidth, float halfrenderheight, const Matrix4x4& mat, HPoint& projected) const
00116 {
00117 projected = HPoint(x, y, z, 1.0f) * mat;
00118 projected.w = 1.0f / projected.w;
00119
00120 projected.x*=projected.w;
00121 projected.y*=projected.w;
00122 projected.z*=projected.w;
00123
00124 projected.x *= halfrenderwidth; projected.x += halfrenderwidth;
00125 projected.y *= -halfrenderheight; projected.y += halfrenderheight;
00126 }
00127
00128 void Point::SetNotUsed()
00129 {
00130
00131 IR(x) = 0xffffffff;
00132 IR(y) = 0xffffffff;
00133 IR(z) = 0xffffffff;
00134 }
00135
00136 BOOL Point::IsNotUsed() const
00137 {
00138 if(IR(x)!=0xffffffff) return FALSE;
00139 if(IR(y)!=0xffffffff) return FALSE;
00140 if(IR(z)!=0xffffffff) return FALSE;
00141 return TRUE;
00142 }
00143
00144 Point& Point::Mult(const Matrix3x3& mat, const Point& a)
00145 {
00146 x = a.x * mat.m[0][0] + a.y * mat.m[0][1] + a.z * mat.m[0][2];
00147 y = a.x * mat.m[1][0] + a.y * mat.m[1][1] + a.z * mat.m[1][2];
00148 z = a.x * mat.m[2][0] + a.y * mat.m[2][1] + a.z * mat.m[2][2];
00149 return *this;
00150 }
00151
00152 Point& Point::Mult2(const Matrix3x3& mat1, const Point& a1, const Matrix3x3& mat2, const Point& a2)
00153 {
00154 x = a1.x * mat1.m[0][0] + a1.y * mat1.m[0][1] + a1.z * mat1.m[0][2] + a2.x * mat2.m[0][0] + a2.y * mat2.m[0][1] + a2.z * mat2.m[0][2];
00155 y = a1.x * mat1.m[1][0] + a1.y * mat1.m[1][1] + a1.z * mat1.m[1][2] + a2.x * mat2.m[1][0] + a2.y * mat2.m[1][1] + a2.z * mat2.m[1][2];
00156 z = a1.x * mat1.m[2][0] + a1.y * mat1.m[2][1] + a1.z * mat1.m[2][2] + a2.x * mat2.m[2][0] + a2.y * mat2.m[2][1] + a2.z * mat2.m[2][2];
00157 return *this;
00158 }
00159
00160 Point& Point::Mac(const Matrix3x3& mat, const Point& a)
00161 {
00162 x += a.x * mat.m[0][0] + a.y * mat.m[0][1] + a.z * mat.m[0][2];
00163 y += a.x * mat.m[1][0] + a.y * mat.m[1][1] + a.z * mat.m[1][2];
00164 z += a.x * mat.m[2][0] + a.y * mat.m[2][1] + a.z * mat.m[2][2];
00165 return *this;
00166 }
00167
00168 Point& Point::TransMult(const Matrix3x3& mat, const Point& a)
00169 {
00170 x = a.x * mat.m[0][0] + a.y * mat.m[1][0] + a.z * mat.m[2][0];
00171 y = a.x * mat.m[0][1] + a.y * mat.m[1][1] + a.z * mat.m[2][1];
00172 z = a.x * mat.m[0][2] + a.y * mat.m[1][2] + a.z * mat.m[2][2];
00173 return *this;
00174 }
00175
00176 Point& Point::Transform(const Point& r, const Matrix3x3& rotpos, const Point& linpos)
00177 {
00178 x = r.x * rotpos.m[0][0] + r.y * rotpos.m[0][1] + r.z * rotpos.m[0][2] + linpos.x;
00179 y = r.x * rotpos.m[1][0] + r.y * rotpos.m[1][1] + r.z * rotpos.m[1][2] + linpos.y;
00180 z = r.x * rotpos.m[2][0] + r.y * rotpos.m[2][1] + r.z * rotpos.m[2][2] + linpos.z;
00181 return *this;
00182 }
00183
00184 Point& Point::InvTransform(const Point& r, const Matrix3x3& rotpos, const Point& linpos)
00185 {
00186 float sx = r.x - linpos.x;
00187 float sy = r.y - linpos.y;
00188 float sz = r.z - linpos.z;
00189 x = sx * rotpos.m[0][0] + sy * rotpos.m[1][0] + sz * rotpos.m[2][0];
00190 y = sx * rotpos.m[0][1] + sy * rotpos.m[1][1] + sz * rotpos.m[2][1];
00191 z = sx * rotpos.m[0][2] + sy * rotpos.m[1][2] + sz * rotpos.m[2][2];
00192 return *this;
00193 }