2 * ***** BEGIN GPL LICENSE BLOCK *****
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software Foundation,
16 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
19 * All rights reserved.
21 * The Original Code is: all of this file.
23 * Contributor(s): none yet.
25 * ***** END GPL LICENSE BLOCK *****
28 /** \file gameengine/Rasterizer/RAS_TexVert.cpp
33 #include "RAS_TexVert.h"
34 #include "MT_Matrix4x4.h"
36 RAS_TexVert::RAS_TexVert(const MT_Point3& xyz,
39 const MT_Vector4& tangent,
40 const unsigned int rgba,
41 const MT_Vector3& normal,
43 const unsigned int origindex)
45 xyz.getValue(m_localxyz);
50 tangent.getValue(m_tangent);
51 m_flag = (flat)? FLAT: 0;
52 m_origindex = origindex;
57 const MT_Point3& RAS_TexVert::xyz()
59 g_pt3.setValue(m_localxyz);
63 void RAS_TexVert::SetRGBA(const MT_Vector4& rgba)
65 unsigned char *colp = (unsigned char*) &m_rgba;
66 colp[0] = (unsigned char) (rgba[0] * 255.0);
67 colp[1] = (unsigned char) (rgba[1] * 255.0);
68 colp[2] = (unsigned char) (rgba[2] * 255.0);
69 colp[3] = (unsigned char) (rgba[3] * 255.0);
73 void RAS_TexVert::SetXYZ(const MT_Point3& xyz)
75 xyz.getValue(m_localxyz);
78 void RAS_TexVert::SetXYZ(const float *xyz)
80 m_localxyz[0] = xyz[0]; m_localxyz[1] = xyz[1]; m_localxyz[2] = xyz[2];
83 void RAS_TexVert::SetUV(const MT_Point2& uv)
88 void RAS_TexVert::SetUV2(const MT_Point2& uv)
94 void RAS_TexVert::SetRGBA(const unsigned int rgba)
100 void RAS_TexVert::SetFlag(const short flag)
105 void RAS_TexVert::SetUnit(const unsigned int u)
107 m_unit = u <= (unsigned int) MAX_UNIT ? u: (unsigned int)MAX_UNIT;
110 void RAS_TexVert::SetNormal(const MT_Vector3& normal)
112 normal.getValue(m_normal);
115 void RAS_TexVert::SetTangent(const MT_Vector3& tangent)
117 tangent.getValue(m_tangent);
121 // compare two vertices, and return TRUE if both are almost identical (they can be shared)
122 bool RAS_TexVert::closeTo(const RAS_TexVert* other)
125 /* m_flag == other->m_flag && */
126 /* at the moment the face only stores the smooth/flat setting so don't bother comparing it */
127 m_rgba == other->m_rgba &&
128 MT_fuzzyEqual(MT_Vector3(m_normal), MT_Vector3(other->m_normal)) &&
129 MT_fuzzyEqual(MT_Vector3(m_tangent), MT_Vector3(other->m_tangent)) &&
130 MT_fuzzyEqual(MT_Vector2(m_uv1), MT_Vector2(other->m_uv1)) &&
131 MT_fuzzyEqual(MT_Vector2(m_uv2), MT_Vector2(other->m_uv2)) /* &&
132 MT_fuzzyEqual(MT_Vector3(m_localxyz), MT_Vector3(other->m_localxyz))*/);
133 /* don't bother comparing m_localxyz since we know there from the same vert */
136 short RAS_TexVert::getFlag() const
142 unsigned int RAS_TexVert::getUnit() const
147 void RAS_TexVert::Transform(const MT_Matrix4x4& mat, const MT_Matrix4x4& nmat)
149 SetXYZ((mat*MT_Vector4(m_localxyz[0], m_localxyz[1], m_localxyz[2], 1.0)).getValue());
150 SetNormal((nmat*MT_Vector4(m_normal[0], m_normal[1], m_normal[2], 1.0)).getValue());
151 SetTangent((nmat*MT_Vector4(m_tangent[0], m_tangent[1], m_tangent[2], 1.0)).getValue());