Initial
This commit is contained in:
26
engine/VECTOR3D.CPP
Normal file
26
engine/VECTOR3D.CPP
Normal file
@@ -0,0 +1,26 @@
|
||||
#include <engine/vector3d.hpp>
|
||||
|
||||
void Vector3D::normalize(void)
|
||||
{
|
||||
mNormalVector.xScalar(0);
|
||||
mNormalVector.yScalar(0);
|
||||
mNormalVector.zScalar(0);
|
||||
Point3D currVertex;
|
||||
Point3D nextVertex;
|
||||
|
||||
for(int index=0;index<VectorPoints;index++)
|
||||
{
|
||||
if(index==VectorPoints-1)nextVertex=mVector3D[0];
|
||||
else nextVertex=mVector3D[index+1];
|
||||
currVertex=mVector3D[index];
|
||||
mNormalVector.xScalar(mNormalVector.xScalar()+((currVertex.y()-nextVertex.y())*(currVertex.z()+nextVertex.z())));
|
||||
mNormalVector.yScalar(mNormalVector.yScalar()+((currVertex.z()-nextVertex.z())*(currVertex.x()+nextVertex.x())));
|
||||
mNormalVector.zScalar(mNormalVector.zScalar()+((currVertex.x()-nextVertex.x())*(currVertex.y()+nextVertex.y())));
|
||||
}
|
||||
if(mNormalVector.xScalar()<0)mNormalVector.xScalar(-1);
|
||||
else if(mNormalVector.xScalar()>0)mNormalVector.xScalar(1);
|
||||
if(mNormalVector.yScalar()<0)mNormalVector.yScalar(-1);
|
||||
else if(mNormalVector.yScalar()>0)mNormalVector.yScalar(1);
|
||||
if(mNormalVector.zScalar()<0)mNormalVector.zScalar(-1);
|
||||
else if(mNormalVector.zScalar()>0)mNormalVector.zScalar(1);
|
||||
}
|
||||
Reference in New Issue
Block a user