| 1 |
/****************************************************************************** |
| 2 |
This source file is part of the Avogadro project. |
| 3 |
This source code is released under the 3-Clause BSD License, (see "LICENSE"). |
| 4 |
******************************************************************************/ |
| 5 |
|
| 6 |
#include "quad.h" |
| 7 |
|
| 8 |
using Avogadro::Core::Array; |
| 9 |
|
| 10 |
namespace Avogadro::Rendering { |
| 11 |
|
| 12 |
void Quad::setQuad(const Vector3f& topLeft, const Vector3f& topRight, |
| 13 |
const Vector3f& bottomLeft, const Vector3f& bottomRight) |
| 14 |
{ |
| 15 |
const Vector3f bottom = bottomRight - bottomLeft; |
| 16 |
const Vector3f left = topLeft - bottomLeft; |
| 17 |
const Vector3f normal = bottom.cross(left).normalized(); |
| 18 |
Array<Vector3f> norms(4, normal); |
| 19 |
|
| 20 |
Array<Vector3f> verts(4); |
| 21 |
verts[0] = topLeft; |
| 22 |
verts[1] = topRight; |
| 23 |
verts[2] = bottomLeft; |
| 24 |
verts[3] = bottomRight; |
| 25 |
|
| 26 |
Array<unsigned int> indices(6); |
| 27 |
indices[0] = 0; |
| 28 |
indices[1] = 1; |
| 29 |
indices[2] = 2; |
| 30 |
indices[3] = 2; |
| 31 |
indices[4] = 1; |
| 32 |
indices[5] = 3; |
| 33 |
|
| 34 |
clear(); |
| 35 |
addVertices(verts, norms); |
| 36 |
addTriangles(indices); |
| 37 |
} |
| 38 |
|
| 39 |
} // End namespace Avogadro::Rendering |