MRPT  2.0.1
TTriangle.cpp
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | https://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2020, Individual contributors, see AUTHORS file |
6  | See: https://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See: https://www.mrpt.org/License |
8  +------------------------------------------------------------------------+ */
9 
10 #include "opengl-precomp.h" // Precompiled header
11 
12 #include <mrpt/opengl/TTriangle.h>
14 
15 using namespace mrpt::opengl;
16 
17 // packet size= 3 vertices, each:
18 // XYZ (float) + normal (XYZ float) + RGBA (u8) + UV (float)
19 static_assert(sizeof(TTriangle) == (sizeof(float) * (3 + 3 + 2) + 4) * 3);
20 
22 {
23  const float ax = x(1) - x(0);
24  const float ay = y(1) - y(0);
25  const float az = z(1) - z(0);
26  const float bx = x(2) - x(0);
27  const float by = y(2) - y(0);
28  const float bz = z(2) - z(0);
29 
30  const mrpt::math::TVector3Df no = {ay * bz - az * by, -ax * bz + az * bx,
31  ax * by - ay * bx};
32  for (auto& v : vertices) v.normal = no;
33 }
34 
36 {
37  for (const auto& p : vertices)
38  {
39  const auto& pp = p.xyzrgba;
40  o << pp.pt << pp.r << pp.g << pp.b << pp.a << p.normal;
41  }
42 }
44 {
45  for (auto& p : vertices)
46  {
47  auto& pp = p.xyzrgba;
48  in >> pp.pt >> pp.r >> pp.g >> pp.b >> pp.a >> p.normal;
49  }
50 }
const float & x(size_t i) const
Definition: TTriangle.h:90
void readFrom(mrpt::serialization::CArchive &i)
Definition: TTriangle.cpp:43
A triangle (float coordinates) with RGBA colors (u8) and UV (texture coordinates) for each vertex...
Definition: TTriangle.h:35
std::array< Vertex, 3 > vertices
Definition: TTriangle.h:88
const float & y(size_t i) const
Definition: TTriangle.h:91
Virtual base class for "archives": classes abstracting I/O streams.
Definition: CArchive.h:54
const float & z(size_t i) const
Definition: TTriangle.h:92
The namespace for 3D scene representation and rendering.
Definition: CGlCanvasBase.h:13
void computeNormals()
Compute the three normals from the cross-product of "v01 x v02".
Definition: TTriangle.cpp:21
const float & v(size_t i) const
Definition: TTriangle.h:98
void writeTo(mrpt::serialization::CArchive &o) const
Definition: TTriangle.cpp:35



Page generated by Doxygen 1.8.14 for MRPT 2.0.1 Git: 0fef1a6d7 Fri Apr 3 23:00:21 2020 +0200 at vie abr 3 23:20:28 CEST 2020