IcePoint.cpp
Go to the documentation of this file.
1 
8 
11 
45 
48 // Precompiled Header
49 #include "Stdafx.h"
50 
51 using namespace IceMaths;
52 
54 
60 {
61  x = UnitRandomFloat();
62  y = UnitRandomFloat();
63  z = UnitRandomFloat();
64  Normalize();
65  return *this;
66 }
67 
69 
75 {
76  x = UnitRandomFloat() - 0.5f;
77  y = UnitRandomFloat() - 0.5f;
78  z = UnitRandomFloat() - 0.5f;
79  Normalize();
80  return *this;
81 }
82 
83 // Cast operator
84 // WARNING: not inlined
85 Point::operator HPoint() const { return HPoint(x, y, z, 0.0f); }
86 
87 Point& Point::Refract(const Point& eye, const Point& n, float refractindex, Point& refracted)
88 {
89  // Point EyePt = eye position
90  // Point p = current vertex
91  // Point n = vertex normal
92  // Point rv = refracted vector
93  // Eye vector - doesn't need to be normalized
94  Point Env;
95  Env.x = eye.x - x;
96  Env.y = eye.y - y;
97  Env.z = eye.z - z;
98 
99  float NDotE = n|Env;
100  float NDotN = n|n;
101  NDotE /= refractindex;
102 
103  // Refracted vector
104  refracted = n*NDotE - Env*NDotN;
105 
106  return *this;
107 }
108 
110 {
111  *this-= (p.d + (*this|p.n))*p.n;
112  return *this;
113 }
114 
115 void Point::ProjectToScreen(float halfrenderwidth, float halfrenderheight, const Matrix4x4& mat, HPoint& projected) const
116 {
117  projected = HPoint(x, y, z, 1.0f) * mat;
118  projected.w = 1.0f / projected.w;
119 
120  projected.x*=projected.w;
121  projected.y*=projected.w;
122  projected.z*=projected.w;
123 
124  projected.x *= halfrenderwidth; projected.x += halfrenderwidth;
125  projected.y *= -halfrenderheight; projected.y += halfrenderheight;
126 }
127 
129 {
130  // We use a particular integer pattern : 0xffffffff everywhere. This is a NAN.
131  IR(x) = 0xffffffff;
132  IR(y) = 0xffffffff;
133  IR(z) = 0xffffffff;
134 }
135 
137 {
138  if(IR(x)!=0xffffffff) return FALSE;
139  if(IR(y)!=0xffffffff) return FALSE;
140  if(IR(z)!=0xffffffff) return FALSE;
141  return TRUE;
142 }
143 
144 Point& Point::Mult(const Matrix3x3& mat, const Point& a)
145 {
146  x = a.x * mat.m[0][0] + a.y * mat.m[0][1] + a.z * mat.m[0][2];
147  y = a.x * mat.m[1][0] + a.y * mat.m[1][1] + a.z * mat.m[1][2];
148  z = a.x * mat.m[2][0] + a.y * mat.m[2][1] + a.z * mat.m[2][2];
149  return *this;
150 }
151 
152 Point& Point::Mult2(const Matrix3x3& mat1, const Point& a1, const Matrix3x3& mat2, const Point& a2)
153 {
154  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];
155  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];
156  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];
157  return *this;
158 }
159 
160 Point& Point::Mac(const Matrix3x3& mat, const Point& a)
161 {
162  x += a.x * mat.m[0][0] + a.y * mat.m[0][1] + a.z * mat.m[0][2];
163  y += a.x * mat.m[1][0] + a.y * mat.m[1][1] + a.z * mat.m[1][2];
164  z += a.x * mat.m[2][0] + a.y * mat.m[2][1] + a.z * mat.m[2][2];
165  return *this;
166 }
167 
168 Point& Point::TransMult(const Matrix3x3& mat, const Point& a)
169 {
170  x = a.x * mat.m[0][0] + a.y * mat.m[1][0] + a.z * mat.m[2][0];
171  y = a.x * mat.m[0][1] + a.y * mat.m[1][1] + a.z * mat.m[2][1];
172  z = a.x * mat.m[0][2] + a.y * mat.m[1][2] + a.z * mat.m[2][2];
173  return *this;
174 }
175 
176 Point& Point::Transform(const Point& r, const Matrix3x3& rotpos, const Point& linpos)
177 {
178  x = r.x * rotpos.m[0][0] + r.y * rotpos.m[0][1] + r.z * rotpos.m[0][2] + linpos.x;
179  y = r.x * rotpos.m[1][0] + r.y * rotpos.m[1][1] + r.z * rotpos.m[1][2] + linpos.y;
180  z = r.x * rotpos.m[2][0] + r.y * rotpos.m[2][1] + r.z * rotpos.m[2][2] + linpos.z;
181  return *this;
182 }
183 
184 Point& Point::InvTransform(const Point& r, const Matrix3x3& rotpos, const Point& linpos)
185 {
186  float sx = r.x - linpos.x;
187  float sy = r.y - linpos.y;
188  float sz = r.z - linpos.z;
189  x = sx * rotpos.m[0][0] + sy * rotpos.m[1][0] + sz * rotpos.m[2][0];
190  y = sx * rotpos.m[0][1] + sy * rotpos.m[1][1] + sz * rotpos.m[2][1];
191  z = sx * rotpos.m[0][2] + sy * rotpos.m[1][2] + sz * rotpos.m[2][2];
192  return *this;
193 }
inline_ Point & Mac(const Point &a, const Point &b, float scalar)
this = a + b * scalar
Definition: OPC_IceHook.h:100
#define IR(x)
Integer representation of a floating-point value.
Definition: IceFPU.h:18
#define FALSE
Definition: OPC_IceHook.h:9
Point & PositiveUnitRandomVector()
Sets positive unit random vector.
Definition: IcePoint.cpp:59
#define TRUE
Definition: OPC_IceHook.h:13
inline_ Point & Transform(const Point &r, const Matrix3x3 &rotpos, const Point &linpos)
this = rotpos * r + linpos
Definition: IcePoint.cpp:176
int BOOL
Another boolean type.
Definition: IceTypes.h:102
inline_ Point & Mult2(const Matrix3x3 &mat1, const Point &a1, const Matrix3x3 &mat2, const Point &a2)
this = mat1 * a1 + mat2 * a2
Definition: IcePoint.cpp:152
Point n
The normal to the plane.
Definition: OPC_IceHook.h:54
void ProjectToScreen(float halfrenderwidth, float halfrenderheight, const Matrix4x4 &mat, HPoint &projected) const
Projects the point onto the screen.
Definition: IcePoint.cpp:115
Point & UnitRandomVector()
Sets unit random vector.
Definition: IcePoint.cpp:74
inline_ float UnitRandomFloat()
Returns a unit random floating-point value.
Definition: IceRandom.h:19
void SetNotUsed()
Stuff magic values in the point, marking it as explicitely not used.
Definition: IcePoint.cpp:128
BOOL IsNotUsed() const
Checks the point is marked as not used.
Definition: IcePoint.cpp:136
float w
Cast a HPoint to a Point. w is discarded.
Definition: OPC_IceHook.h:157
inline_ Point & Normalize()
Normalizes the vector.
Definition: OPC_IceHook.h:270
Point & ProjectToPlane(const Plane &p)
Projects the point onto a plane.
Definition: IcePoint.cpp:109
inline_ Point & Mult(float s)
Multiplies by a scalar.
Definition: OPC_IceHook.h:88
Point & Refract(const Point &eye, const Point &n, float refractindex, Point &refracted)
Refracts the point.
Definition: IcePoint.cpp:87
inline_ Point & InvTransform(const Point &r, const Matrix3x3 &rotpos, const Point &linpos)
this = trans(rotpos) * (r - linpos)
Definition: IcePoint.cpp:184
float d
The distance from the origin.
Definition: OPC_IceHook.h:55
inline_ Point & TransMult(const Matrix3x3 &mat, const Point &a)
this = transpose(mat) * a
Definition: IcePoint.cpp:168


openhrp3
Author(s): AIST, General Robotix Inc., Nakamura Lab of Dept. of Mechano Informatics at University of Tokyo
autogenerated on Sat Apr 13 2019 02:14:22