zenilib: zenilib/jni/external/zenilib/zeni_graphics/EZ2D.cpp Source File

zenilib 0.5.3.0

- Main Page
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

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
22 void render_image(
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
45 void render_image(
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
74 Vertex2f_Texture vt;
75 Quadrilateral<Vertex2f_Texture> q( (Vertex2f_Texture(Point2f(about3 + ulv), Point2f(tx0, 0.0f))) ,
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
91 int sprite_num_frames(
92 const String &sprite) {
93
94 return get_Textures().get_num_frames(
95 get_Textures().get_id(sprite));
96 }
97
98 void set_sprite_frame(
99 const String &sprite,
100 const int &frame_number) {
101
102 return get_Textures().set_current_frame(
103 get_Textures().get_id(sprite),
104 frame_number);
105 }
106
107 void increment_sprite_frame(
108 const String &sprite_name) {
109
110 Texture &texture = get_Textures()
111 [get_Textures().get_id(sprite_name)];
112
113 Sprite * const sprite = dynamic_cast< Sprite *>(&texture);
114
115 if(!sprite)
116 throw Sprite_Function_Misapplied();
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
128 void decrement_sprite_frame(
129 const String &sprite_name) {
130
131 Texture &texture = get_Textures()
132 [get_Textures().get_id(sprite_name)];
133
134 Sprite * const sprite = dynamic_cast< Sprite *>(&texture);
135
136 if(!sprite)
137 throw Sprite_Function_Misapplied();
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 }
f
GLclampf f
Definition: glew.h:3390
Zeni::Vector3f::set_spherical
void set_spherical(const float &theta, const float &phi, const float &magnitude=1)
Set the vector using spherical coordinates.
Definition: Vector3f.cpp:93
Zeni::Textures::set_current_frame
void set_current_frame(const unsigned long &id, const int &frame_number)
Set the frame number for a Sprite.
Definition: Textures.cpp:96
Zeni::Material
An Abstraction of a Material.
Definition: Material.h:56
Zeni::Database::get_id
unsigned long get_id(const String &name) const
Get an id by name, possibly throwing an Error.
Definition: Database.hxx:172
Zeni::increment_sprite_frame
void increment_sprite_frame(const String &sprite_name)
Definition: EZ2D.cpp:107
Zeni::Quadrilateral
An Abstraction of a Quadrilateral.
Definition: Quadrilateral.h:37
Zeni::Textures::get_num_frames
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
Zeni::render_image
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
Zeni::Vector3f::magnitude
float magnitude() const
Get the magnitude of the vector.
Definition: Vector3f.hxx:142
Zeni::String
Definition: String.h:29
Zeni::Point3f
A 3D Point represented with floats.
Definition: Coordinate.h:133
Zeni::Sprite_Function_Misapplied
Definition: Textures.h:145
Zeni::Point2f::y
float y
Definition: Coordinate.h:117
Zeni::Texture
An Abstraction of a Texture.
Definition: Texture.h:61
Zeni::Vector3f
A Featureful 3-Space Vector Class.
Definition: Vector3f.h:58
Zeni::Sprite::set_current_frame
void set_current_frame(const int &frame_number)
Set this frame.
Definition: Texture.cpp:112
Zeni::Video::render
virtual void render(const Renderable &renderable)=0
Render a Renderable.
Zeni::Vector3f::theta
float theta() const
theta == radians north of vector i
Definition: Vector3f.cpp:69
Zeni::decrement_sprite_frame
void decrement_sprite_frame(const String &sprite_name)
Definition: EZ2D.cpp:128
Zeni::Point2f::x
float x
Definition: Coordinate.h:117
Zeni::get_Textures
Textures & get_Textures()
Get access to the singleton.
Definition: Textures.cpp:64
Zeni::Sprite
Definition: Texture.h:77
texture
GLenum GLenum GLuint texture
Definition: gl2ext.h:850
Zeni::Vertex2f_Texture
An Abstraction of a Vertex in 2-space, textured.
Definition: Vertex2f.h:115
Zeni::is_sprite
bool is_sprite(const String &sprite)
Definition: EZ2D.cpp:84
Zeni::Sprite::get_current_frame
int get_current_frame() const
Get the currently selected frame number.
Definition: Texture.cpp:106
Zeni::Vector3f::phi
float phi() const
phi == radians down from k
Definition: Vector3f.cpp:81
q
GLdouble GLdouble GLdouble GLdouble q
Definition: glew.h:1400
Zeni::Sprite::get_num_frames
int get_num_frames() const
Get the number of frames.
Definition: Texture.cpp:102
Zeni::sprite_num_frames
int sprite_num_frames(const String &sprite)
Definition: EZ2D.cpp:91
Zeni::Textures::is_Sprite
bool is_Sprite(const unsigned long &id)
Does this id point to a Sprite.
Definition: Textures.cpp:76
Zeni::get_Video
Video & get_Video()
Get access to the singleton.
Definition: Video.cpp:149
Zeni::set_sprite_frame
void set_sprite_frame(const String &sprite, const int &frame_number)
Definition: EZ2D.cpp:98
zeni_graphics.h
Zeni::Renderable::lend_Material
void lend_Material(const Material *const &material)
Set the Material, giving the Renderable no ownership.
Definition: Renderable.cpp:41
Zeni::Point2f
A 2D Point represented with floats.
Definition: Coordinate.h:98
Zeni::Color
Color.
Definition: Color.h:41
frameno
long frameno
Definition: psytune.c:227