zenilib  0.5.3.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Triangle.hxx
Go to the documentation of this file.
1 /* This file is part of the Zenipex Library (zenilib).
2  * Copyright (C) 2011 Mitchell Keith Bloch (bazald).
3  *
4  * zenilib is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * zenilib 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 Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public License
15  * along with zenilib. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #ifndef ZENI_TRIANGLE_HXX
19 #define ZENI_TRIANGLE_HXX
20 
21 // HXXed below
22 #include <Zeni/Vertex3f.h>
23 #include <Zeni/Video_DX9.h>
24 
25 #include <Zeni/Triangle.h>
26 
27 // Not HXXed
28 #include <Zeni/Vector3f.h>
29 
30 #if defined(REQUIRE_GL_ES)
31 #include <GLES/gl.h>
32 #else
33 #include <GL/glew.h>
34 #endif
35 
36 #include <cassert>
37 
38 #include <Zeni/Define.h>
39 
40 namespace Zeni {
41 
42  template <typename VERTEX>
44  : a(VERTEX()),
45  b(VERTEX()),
46  c(VERTEX())
47  {
48  }
49 
50  template <typename VERTEX>
51  Triangle<VERTEX>::Triangle(const VERTEX &vertex0, const VERTEX &vertex1, const VERTEX &vertex2)
52  : a(vertex0),
53  b(vertex1),
54  c(vertex2)
55  {
56  }
57 
58  template <typename VERTEX>
60  : Renderable(rhs),
61  a(rhs.a),
62  b(rhs.b),
63  c(rhs.c)
64  {
65  }
66 
67  template <typename VERTEX>
69  static_cast<Renderable &>(*this) = rhs;
70 
71  a = rhs.a;
72  b = rhs.b;
73  c = rhs.c;
74 
75  return *this;
76  }
77 
78  template <typename VERTEX>
79  bool Triangle<VERTEX>::is_3d() const {
80  return a.is_3d();
81  }
82 
83 #if !defined(DISABLE_GL) && !defined(REQUIRE_GL_ES)
84  template <typename VERTEX>
87  a.subrender_to(screen);
88  b.subrender_to(screen);
89  c.subrender_to(screen);
90  glEnd();
91  }
92 #endif
93 
94 #ifndef DISABLE_DX9
95  template <typename VERTEX>
96  void Triangle<VERTEX>::render_to(Video_DX9 &screen) const {
97  screen.get_d3d_device()->DrawPrimitiveUP(D3DPT_TRIANGLELIST, 1, a.get_address(), sizeof(VERTEX));
98  }
99 #endif
100 
101  template <typename VERTEX>
103  return new Triangle<VERTEX>(*this);
104  }
105 
106  template <typename VERTEX>
108  std::auto_ptr<VERTEX> b2(b.interpolate_to(0.5f, a));
109  std::auto_ptr<VERTEX> c2(c.interpolate_to(0.5f, a));
110  Triangle<VERTEX> * triangle = new Triangle<VERTEX>(a, *b2, *c2);
111  triangle->fax_Material(get_Material());
112  return triangle;
113  }
114 
115  template <typename VERTEX>
117  std::auto_ptr<VERTEX> a2(a.interpolate_to(0.5f, b));
118  std::auto_ptr<VERTEX> c2(c.interpolate_to(0.5f, b));
119  Triangle<VERTEX> * triangle = new Triangle<VERTEX>(*a2, b, *c2);
120  triangle->fax_Material(get_Material());
121  return triangle;
122  }
123 
124  template <typename VERTEX>
126  std::auto_ptr<VERTEX> a2(a.interpolate_to(0.5f, c));
127  std::auto_ptr<VERTEX> b2(b.interpolate_to(0.5f, c));
128  Triangle<VERTEX> * triangle = new Triangle<VERTEX>(*a2, *b2, c);
129  triangle->fax_Material(get_Material());
130  return triangle;
131  }
132 
133  template <typename VERTEX>
135  std::auto_ptr<VERTEX> a2(a.interpolate_to(0.5f, b));
136  std::auto_ptr<VERTEX> b2(b.interpolate_to(0.5f, c));
137  std::auto_ptr<VERTEX> c2(c.interpolate_to(0.5f, a));
138  Triangle<VERTEX> * triangle = new Triangle<VERTEX>(*a2, *b2, *c2);
139  triangle->fax_Material(get_Material());
140  return triangle;
141  }
142 
143  template <typename VERTEX>
144  const VERTEX & Triangle<VERTEX>::operator[](const int &index) const {
145  assert(-1 < index && index < 3);
146  const VERTEX * const ptr = &a;
147  return ptr[index];
148  }
149 
150  template <typename VERTEX>
151  VERTEX & Triangle<VERTEX>::operator[](const int &index) {
152  assert(-1 < index && index < 3);
153  VERTEX * const ptr = &a;
154  return ptr[index];
155  }
156 
157 }
158 
159 #include <Zeni/Undefine.h>
160 
161 #include <Zeni/Video_DX9.hxx>
162 #include <Zeni/Vertex3f.hxx>
163 
164 #endif
The Direct3D9 Rendering System.
Definition: Video_DX9.h:62
LPDIRECT3DDEVICE9 & get_d3d_device()
See DirectX Documentation for details.
Definition: Video_DX9.hxx:48
VERTEX a
Definition: Triangle.h:72
Triangle< VERTEX > * get_duplicate_subt1() const
Get quarter 1 of the Triangle; Can be used for software LOD increase.
Definition: Triangle.hxx:116
Triangle< VERTEX > & operator=(const Triangle< VERTEX > &rhs)
Definition: Triangle.hxx:68
GLboolean GLboolean GLboolean GLboolean a
Definition: glew.h:8736
#define assert(x)
Definition: SDL_malloc.c:1234
A Renderable Interface.
Definition: Renderable.h:47
Triangle< VERTEX > * get_duplicate() const
Get a duplicate of the Triangle.
Definition: Triangle.hxx:102
Triangle< VERTEX > * get_duplicate_subt2() const
Get quarter 2 of the Triangle; Can be used for software LOD increase.
Definition: Triangle.hxx:125
Triangle< VERTEX > * get_duplicate_subt3() const
Get quarter 3 of the Triangle; Can be used for software LOD increase.
Definition: Triangle.hxx:134
Triangle< VERTEX > * get_duplicate_subt0() const
Get quarter 0 of the Triangle; Can be used for software LOD increase.
Definition: Triangle.hxx:107
#define GL_TRIANGLES
Definition: gl2.h:58
The OpenGL Rendering System.
VERTEX c
Definition: Triangle.h:74
const GLfloat * c
Definition: glew.h:14913
GLuint index
Definition: glew.h:1800
VERTEX b
Definition: Triangle.h:73
virtual void render_to(Video_GL_Fixed &screen) const
Overridden for OpenGL rendering.
Definition: Triangle.hxx:85
virtual bool is_3d() const
Tell the rendering system if we&#39;re using 3D coordinates.
Definition: Triangle.hxx:79
GLdouble GLdouble GLdouble b
Definition: glew.h:8383
An Abstraction of a Triangle.
Definition: Triangle.h:36
#define glBegin
Definition: gl_mangle.h:56
#define glEnd
Definition: gl_mangle.h:450
const VERTEX & operator[](const int &index) const
Get &#39;index&#39;.
Definition: Triangle.hxx:144