zenilib  0.5.3.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
EZ2D.cpp
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 #include <zeni_graphics.h>
19 
20 namespace Zeni {
21 
23  const String &image_name,
24  const Point2f &upper_left,
25  const Point2f &lower_right,
26  const bool &horizontally_flipped,
27  const Color &color_filter) {
28 
29  float
30  tx0 = horizontally_flipped ? 1.0f : 0.0f,
31  tx1 = 1.0f - tx0;
32 
33  Material material(image_name, color_filter);
34 
35  Quadrilateral<Vertex2f_Texture> q( (Vertex2f_Texture(Point2f(upper_left.x, upper_left.y), Point2f(tx0, 0.0f))) ,
36  (Vertex2f_Texture(Point2f(upper_left.x, lower_right.y), Point2f(tx0, 1.0f))) ,
37  (Vertex2f_Texture(Point2f(lower_right.x, lower_right.y), Point2f(tx1, 1.0f))) ,
38  (Vertex2f_Texture(Point2f(lower_right.x, upper_left.y), Point2f(tx1, 0.0f))) );
39  q.lend_Material(&material);
40 
41  get_Video().render(q);
42  }
43 
44 
46  const String &image_name,
47  const Point2f &upper_left,
48  const Point2f &lower_right,
49  const float &radians_ccw,
50  const float &scaling_factor,
51  const Point2f &about,
52  const bool &horizontally_flipped,
53  const Color &color_filter) {
54 
55  const Point3f about3 = Point3f(about);
56 
57  Vector3f
58  ulv = Point3f(upper_left) - about3,
59  llv = Point3f(upper_left.x, lower_right.y, 0.0f) - about3,
60  lrv = Point3f(lower_right) - about3,
61  urv = Point3f(lower_right.x, upper_left.y, 0.0f) - about3;
62 
63  ulv.set_spherical(ulv.theta() - radians_ccw, ulv.phi(), ulv.magnitude() * scaling_factor);
64  llv.set_spherical(llv.theta() - radians_ccw, llv.phi(), llv.magnitude() * scaling_factor);
65  lrv.set_spherical(lrv.theta() - radians_ccw, lrv.phi(), lrv.magnitude() * scaling_factor);
66  urv.set_spherical(urv.theta() - radians_ccw, urv.phi(), urv.magnitude() * scaling_factor);
67 
68  const float
69  tx0 = horizontally_flipped ? 1.0f : 0.0f,
70  tx1 = 1.0f - tx0;
71 
72  Material material(image_name, color_filter);
73 
76  (Vertex2f_Texture(Point2f(about3 + llv), Point2f(tx0, 1.0f))) ,
77  (Vertex2f_Texture(Point2f(about3 + lrv), Point2f(tx1, 1.0f))) ,
78  (Vertex2f_Texture(Point2f(about3 + urv), Point2f(tx1, 0.0f))) );
79  q.lend_Material(&material);
80 
81  get_Video().render(q);
82  }
83 
84  bool is_sprite(
85  const String &sprite) {
86 
87  return get_Textures().is_Sprite(
88  get_Textures().get_id(sprite));
89  }
90 
92  const String &sprite) {
93 
95  get_Textures().get_id(sprite));
96  }
97 
99  const String &sprite,
100  const int &frame_number) {
101 
103  get_Textures().get_id(sprite),
104  frame_number);
105  }
106 
108  const String &sprite_name) {
109 
111  [get_Textures().get_id(sprite_name)];
112 
113  Sprite * const sprite = dynamic_cast<Sprite *>(&texture);
114 
115  if(!sprite)
117 
118  const int
119  frameno = sprite->get_current_frame(),
120  framecap = sprite->get_num_frames();
121 
122  if(frameno == framecap - 1)
123  sprite->set_current_frame(0);
124  else
125  sprite->set_current_frame(frameno + 1);
126  }
127 
129  const String &sprite_name) {
130 
132  [get_Textures().get_id(sprite_name)];
133 
134  Sprite * const sprite = dynamic_cast<Sprite *>(&texture);
135 
136  if(!sprite)
138 
139  const int
140  frameno = sprite->get_current_frame(),
141  framecap = sprite->get_num_frames();
142 
143  if(frameno)
144  sprite->set_current_frame(frameno - 1);
145  else
146  sprite->set_current_frame(framecap - 1);
147  }
148 
149 }
GLclampf f
Definition: glew.h:3390
void set_spherical(const float &theta, const float &phi, const float &magnitude=1)
Set the vector using spherical coordinates.
Definition: Vector3f.cpp:93
void set_current_frame(const unsigned long &id, const int &frame_number)
Set the frame number for a Sprite.
Definition: Textures.cpp:96
An Abstraction of a Material.
Definition: Material.h:56
unsigned long get_id(const String &name) const
Get an id by name, possibly throwing an Error.
Definition: Database.hxx:172
void increment_sprite_frame(const String &sprite_name)
Definition: EZ2D.cpp:107
An Abstraction of a Quadrilateral.
Definition: Quadrilateral.h:37
int get_num_frames(const unsigned long &id)
Get the number of frames; returns 0 if it is not a Sprite.
Definition: Textures.cpp:80
void render_image(const String &image_name, const Point2f &upper_left, const Point2f &lower_right, const bool &horizontally_flipped, const Color &color_filter)
Definition: EZ2D.cpp:22
float magnitude() const
Get the magnitude of the vector.
Definition: Vector3f.hxx:142
A 3D Point represented with floats.
Definition: Coordinate.h:133
An Abstraction of a Texture.
Definition: Texture.h:61
A Featureful 3-Space Vector Class.
Definition: Vector3f.h:58
void set_current_frame(const int &frame_number)
Set this frame.
Definition: Texture.cpp:112
virtual void render(const Renderable &renderable)=0
Render a Renderable.
float theta() const
theta == radians north of vector i
Definition: Vector3f.cpp:69
void decrement_sprite_frame(const String &sprite_name)
Definition: EZ2D.cpp:128
Textures & get_Textures()
Get access to the singleton.
Definition: Textures.cpp:64
GLenum GLenum GLuint texture
Definition: gl2ext.h:850
An Abstraction of a Vertex in 2-space, textured.
Definition: Vertex2f.h:115
bool is_sprite(const String &sprite)
Definition: EZ2D.cpp:84
int get_current_frame() const
Get the currently selected frame number.
Definition: Texture.cpp:106
float phi() const
phi == radians down from k
Definition: Vector3f.cpp:81
GLdouble GLdouble GLdouble GLdouble q
Definition: glew.h:1400
int get_num_frames() const
Get the number of frames.
Definition: Texture.cpp:102
int sprite_num_frames(const String &sprite)
Definition: EZ2D.cpp:91
bool is_Sprite(const unsigned long &id)
Does this id point to a Sprite.
Definition: Textures.cpp:76
Video & get_Video()
Get access to the singleton.
Definition: Video.cpp:149
void set_sprite_frame(const String &sprite, const int &frame_number)
Definition: EZ2D.cpp:98
void lend_Material(const Material *const &material)
Set the Material, giving the Renderable no ownership.
Definition: Renderable.cpp:41
A 2D Point represented with floats.
Definition: Coordinate.h:98
Color.
Definition: Color.h:41
long frameno
Definition: psytune.c:227