genode/repos/gems/include/nano3d/cube_shape.h
Norman Feske 259b127f96 Polygon drawing and rudimentary 3D routines
This patch adds two new painters located at gems/include/polygon_gfx.
Both painters draw convex polygons with an arbirary number of points.
The shaded-polygon painter interpolates the color and alpha values
whereas the textured-polygon painter applies a texture to the polygon.
The painters are accompanied by simplistic 3D routines located at
gems/include/nano3d/ and a corresponding example (gems/run/nano3d.run).
2015-07-07 19:48:04 +02:00

70 lines
1.6 KiB
C++

/*
* \brief Cube 3D object
* \author Norman Feske
* \date 2015-06-19
*/
/*
* Copyright (C) 2015 Genode Labs GmbH
*
* This file is part of the Genode OS framework, which is distributed
* under the terms of the GNU General Public License version 2.
*/
#ifndef _INCLUDE__NANO3D__CUBE_SHAPE_H_
#define _INCLUDE__NANO3D__CUBE_SHAPE_H_
#include <nano3d/vertex_array.h>
namespace Nano3d { class Cube_shape; }
class Nano3d::Cube_shape
{
private:
enum { NUM_VERTICES = 8, NUM_FACES = 6 };
typedef Nano3d::Vertex_array<NUM_VERTICES> Vertex_array;
Vertex_array _vertices;
enum { VERTICES_PER_FACE = 4 };
typedef unsigned Face[VERTICES_PER_FACE];
Face _faces[NUM_FACES] { { 0, 1, 3, 2 },
{ 6, 7, 5, 4 },
{ 1, 0, 4, 5 },
{ 3, 1, 5, 7 },
{ 2, 3, 7, 6 },
{ 0, 2, 6, 4 } };
public:
Cube_shape(int size)
{
for (unsigned i = 0; i < NUM_VERTICES; i++)
_vertices[i] = Nano3d::Vertex((i&1) ? size : -size,
(i&2) ? size : -size,
(i&4) ? size : -size);
}
Vertex_array const &vertex_array() const { return _vertices; }
/**
* Call functor 'fn' for each face of the object
*
* The functor is called with an array of 'unsigned' vertex indices
* and the number of indices as arguments.
*/
template <typename FN>
void for_each_face(FN const &fn) const
{
for (unsigned i = 0; i < NUM_FACES; i++)
fn(_faces[i], VERTICES_PER_FACE);
}
};
#endif /* _INCLUDE__NANO3D__CUBE_SHAPE_H_ */