Rev | Line | |
---|
[6] | 1 | #include "OgreMaxVertex.h" |
---|
| 2 | |
---|
| 3 | namespace OgreMax { |
---|
| 4 | |
---|
| 5 | Vertex::Vertex(float x, float y, float z) { |
---|
| 6 | m_position.x = x; |
---|
| 7 | m_position.y = y; |
---|
| 8 | m_position.z = z; |
---|
| 9 | } |
---|
| 10 | |
---|
| 11 | void Vertex::setNormal(float x, float y, float z) { |
---|
| 12 | m_normal.x = x; |
---|
| 13 | m_normal.y = y; |
---|
| 14 | m_normal.z = z; |
---|
| 15 | } |
---|
| 16 | |
---|
| 17 | void Vertex::setColour(float r, float g, float b, float a) { |
---|
| 18 | m_colour.r = r; |
---|
| 19 | m_colour.g = g; |
---|
| 20 | m_colour.b = b; |
---|
| 21 | m_colour.a = a; |
---|
| 22 | } |
---|
| 23 | |
---|
| 24 | void Vertex::addTexCoord(int mapIndex, float u, float v, float w) { |
---|
| 25 | Ogre::Vector3 uvw; |
---|
| 26 | |
---|
| 27 | uvw.x = u; |
---|
| 28 | uvw.y = v; |
---|
| 29 | uvw.z = w; |
---|
| 30 | |
---|
| 31 | m_uvwMap[mapIndex] = uvw; |
---|
| 32 | } |
---|
| 33 | |
---|
| 34 | bool Vertex::hasSameTexCoords(std::map<int, Ogre::Vector3>& uvwMap) { |
---|
| 35 | std::map<int, Ogre::Vector3>::const_iterator it = uvwMap.begin(); |
---|
| 36 | |
---|
| 37 | while (it != uvwMap.end()) { |
---|
| 38 | try { |
---|
| 39 | if (m_uvwMap[it->first] != it->second) |
---|
| 40 | return false; |
---|
| 41 | } |
---|
| 42 | catch (...) { |
---|
| 43 | return false; |
---|
| 44 | } |
---|
| 45 | |
---|
| 46 | ++it; |
---|
| 47 | } |
---|
| 48 | |
---|
| 49 | return true; |
---|
| 50 | } |
---|
| 51 | |
---|
| 52 | bool Vertex::operator == (Vertex& other) { |
---|
| 53 | return ( |
---|
| 54 | m_position == other.m_position && |
---|
| 55 | m_normal == other.m_normal && |
---|
| 56 | m_colour == other.m_colour && |
---|
| 57 | other.hasSameTexCoords(m_uvwMap) |
---|
| 58 | ); |
---|
| 59 | } |
---|
| 60 | |
---|
| 61 | |
---|
| 62 | unsigned int VertexList::add(Vertex& v) { |
---|
| 63 | |
---|
| 64 | int idx = 0; |
---|
| 65 | for (std::list<Vertex>::iterator it = m_vertexList.begin(); it != m_vertexList.end(); ++it, ++idx) { |
---|
| 66 | if (*it == v) |
---|
| 67 | break; |
---|
| 68 | } |
---|
| 69 | |
---|
| 70 | if (it == m_vertexList.end()) |
---|
| 71 | m_vertexList.push_back(v); |
---|
| 72 | |
---|
| 73 | return idx; |
---|
| 74 | } |
---|
| 75 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.