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