Blender V2.61 - r43446

RAS_TexVert.cpp

Go to the documentation of this file.
00001 /*
00002  * ***** BEGIN GPL LICENSE BLOCK *****
00003  *
00004  * This program is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU General Public License
00006  * as published by the Free Software Foundation; either version 2
00007  * of the License, or (at your option) any later version.
00008  *
00009  * This program is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  * GNU General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program; if not, write to the Free Software Foundation,
00016  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00017  *
00018  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
00019  * All rights reserved.
00020  *
00021  * The Original Code is: all of this file.
00022  *
00023  * Contributor(s): none yet.
00024  *
00025  * ***** END GPL LICENSE BLOCK *****
00026  */
00027 
00033 #include "RAS_TexVert.h"
00034 #include "MT_Matrix4x4.h"
00035 
00036 RAS_TexVert::RAS_TexVert(const MT_Point3& xyz,
00037                          const MT_Point2& uv,
00038                          const MT_Point2& uv2,
00039                          const MT_Vector4& tangent,
00040                          const unsigned int rgba,
00041                          const MT_Vector3& normal,
00042                          const bool flat,
00043                          const unsigned int origindex)
00044 {
00045     xyz.getValue(m_localxyz);
00046     uv.getValue(m_uv1);
00047     uv2.getValue(m_uv2);
00048     SetRGBA(rgba);
00049     SetNormal(normal);
00050     tangent.getValue(m_tangent);
00051     m_flag = (flat)? FLAT: 0;
00052     m_origindex = origindex;
00053     m_unit = 2;
00054     m_softBodyIndex = -1;
00055 }
00056 
00057 const MT_Point3& RAS_TexVert::xyz()
00058 {
00059     g_pt3.setValue(m_localxyz);
00060     return g_pt3;
00061 }
00062 
00063 void RAS_TexVert::SetRGBA(const MT_Vector4& rgba)
00064 {
00065     unsigned char *colp = (unsigned char*) &m_rgba;
00066     colp[0] = (unsigned char) (rgba[0]*255.0f);
00067     colp[1] = (unsigned char) (rgba[1]*255.0f);
00068     colp[2] = (unsigned char) (rgba[2]*255.0f);
00069     colp[3] = (unsigned char) (rgba[3]*255.0f);
00070 }
00071 
00072 
00073 void RAS_TexVert::SetXYZ(const MT_Point3& xyz)
00074 {
00075     xyz.getValue(m_localxyz);
00076 }
00077 
00078 void RAS_TexVert::SetXYZ(const float *xyz)
00079 {
00080     m_localxyz[0]= xyz[0]; m_localxyz[1]= xyz[1]; m_localxyz[2]= xyz[2];
00081 }
00082 
00083 void RAS_TexVert::SetUV(const MT_Point2& uv)
00084 {
00085     uv.getValue(m_uv1);
00086 }
00087 
00088 void RAS_TexVert::SetUV2(const MT_Point2& uv)
00089 {
00090     uv.getValue(m_uv2);
00091 }
00092 
00093 
00094 void RAS_TexVert::SetRGBA(const unsigned int rgba)
00095 { 
00096     m_rgba = rgba;
00097 }
00098 
00099 
00100 void RAS_TexVert::SetFlag(const short flag)
00101 {
00102     m_flag = flag;
00103 }
00104 
00105 void RAS_TexVert::SetUnit(const unsigned int u)
00106 {
00107     m_unit = u <= (unsigned int) MAX_UNIT ? u: (unsigned int)MAX_UNIT;
00108 }
00109 
00110 void RAS_TexVert::SetNormal(const MT_Vector3& normal)
00111 {
00112     normal.getValue(m_normal);
00113 }
00114 
00115 void RAS_TexVert::SetTangent(const MT_Vector3& tangent)
00116 {
00117     tangent.getValue(m_tangent);
00118 }
00119 
00120 
00121 // compare two vertices, and return TRUE if both are almost identical (they can be shared)
00122 bool RAS_TexVert::closeTo(const RAS_TexVert* other)
00123 {
00124     return (
00125         /* m_flag == other->m_flag && */
00126         /* at the moment the face only stores the smooth/flat setting so dont bother comparing it */
00127         m_rgba == other->m_rgba &&
00128         MT_fuzzyEqual(MT_Vector3(m_normal), MT_Vector3(other->m_normal)) &&
00129         MT_fuzzyEqual(MT_Vector3(m_tangent), MT_Vector3(other->m_tangent)) &&
00130         MT_fuzzyEqual(MT_Vector2(m_uv1), MT_Vector2(other->m_uv1)) &&
00131         MT_fuzzyEqual(MT_Vector2(m_uv2), MT_Vector2(other->m_uv2)) /* &&
00132         MT_fuzzyEqual(MT_Vector3(m_localxyz), MT_Vector3(other->m_localxyz))*/) ;
00133     /* dont bother comparing m_localxyz since we know there from the same vert */
00134 }
00135 
00136 short RAS_TexVert::getFlag() const
00137 {
00138     return m_flag;
00139 }
00140 
00141 
00142 unsigned int RAS_TexVert::getUnit() const
00143 {
00144     return m_unit;
00145 }
00146 
00147 void RAS_TexVert::Transform(const MT_Matrix4x4& mat, const MT_Matrix4x4& nmat)
00148 {
00149     SetXYZ((mat*MT_Vector4(m_localxyz[0], m_localxyz[1], m_localxyz[2], 1.0)).getValue());
00150     SetNormal((nmat*MT_Vector4(m_normal[0], m_normal[1], m_normal[2], 1.0)).getValue());
00151     SetTangent((nmat*MT_Vector4(m_tangent[0], m_tangent[1], m_tangent[2], 1.0)).getValue());
00152 }
00153