g4tools  5.4.0
Public Member Functions | Public Attributes | List of all members
tools::sg::state Class Reference
Collaboration diagram for tools::sg::state:
Collaboration graph
[legend]

Public Member Functions

 state ()
 
virtual ~state ()
 
 state (const state &a_from)
 
stateoperator= (const state &a_from)
 
bool project_point (float &a_x, float &a_y, float &a_z, float &a_w) const
 
void screen2ndc (int a_x, int a_y, float &a_wcx, float &a_wcy, float &a_wcz, float &a_wcw) const
 
bool screen2wc (int a_x, int a_y, float &a_wcx, float &a_wcy, float &a_wcz) const
 
bool screen2pwc (int a_x, int a_y, float &a_wcx, float &a_wcy, float &a_wcz) const
 
void camera_proj_only (mat4f &a_mtx) const
 

Public Attributes

unsigned int m_ww
 
unsigned int m_wh
 
mat4f m_proj
 
mat4f m_model
 
bool m_GL_DEPTH_TEST
 
bool m_GL_LIGHTING
 
bool m_GL_CULL_FACE
 
bool m_GL_POLYGON_OFFSET_FILL
 
bool m_GL_TEXTURE_2D
 
bool m_GL_POINT_SMOOTH
 
bool m_GL_LINE_SMOOTH
 
bool m_GL_BLEND
 
bool m_use_gsto
 
winding_type m_winding
 
colorf m_color
 
vec3f m_normal
 
unsigned int m_light
 
draw_type m_draw_type
 
shade_type m_shade_model
 
float m_line_width
 
unsigned short m_line_pattern
 
float m_point_size
 
bool m_camera_ortho
 
float m_camera_znear
 
float m_camera_zfar
 
vec3f m_camera_position
 
rotf m_camera_orientation
 
vec4f m_camera_lrbt
 

Detailed Description

Definition at line 25 of file state.

Constructor & Destructor Documentation

◆ state() [1/2]

tools::sg::state::state ( )
inline

Definition at line 30 of file state.

32  :m_ww(0)
33  ,m_wh(0)
34 
35  ,m_GL_DEPTH_TEST(true)
36  ,m_GL_LIGHTING(false)
37  ,m_GL_CULL_FACE(true)
39  ,m_GL_TEXTURE_2D(false)
40  ,m_GL_POINT_SMOOTH(false)
41  ,m_GL_LINE_SMOOTH(false)
42  ,m_GL_BLEND(false)
43 
44  ,m_use_gsto(false)
45 
47  ,m_color(1,1,1,1)
48  ,m_normal(0,0,1)
49 
50  ,m_light(0)
51 
54 
55  ,m_line_width(1)
57  ,m_point_size(1)
58 
59  ,m_camera_ortho(true)
60  ,m_camera_znear(1)
61  ,m_camera_zfar(10)
62  ,m_camera_position(vec3f(0,0,1))
63  ,m_camera_orientation(rotf(vec3f(0,0,1),0))
64  //,m_camera_near_height(0)
65  ,m_camera_lrbt(0,0,0,0)
66  {
67 #ifdef TOOLS_MEM
68  mem::increment(s_class().c_str());
69 #endif
70  //m_proj.set_identity();
71  //m_model.set_identity();
72  }

◆ ~state()

virtual tools::sg::state::~state ( )
inlinevirtual

Definition at line 73 of file state.

73  {
74 #ifdef TOOLS_MEM
75  mem::decrement(s_class().c_str());
76 #endif
77  }

◆ state() [2/2]

tools::sg::state::state ( const state a_from)
inline

Definition at line 79 of file state.

80  :m_ww(a_from.m_ww)
81  ,m_wh(a_from.m_wh)
82 
83  ,m_proj(a_from.m_proj)
84  ,m_model(a_from.m_model)
85 
86  ,m_GL_DEPTH_TEST(a_from.m_GL_DEPTH_TEST)
87  ,m_GL_LIGHTING(a_from.m_GL_LIGHTING)
88  ,m_GL_CULL_FACE(a_from.m_GL_CULL_FACE)
89  ,m_GL_POLYGON_OFFSET_FILL(a_from.m_GL_POLYGON_OFFSET_FILL)
90  ,m_GL_TEXTURE_2D(a_from.m_GL_TEXTURE_2D)
91  ,m_GL_POINT_SMOOTH(a_from.m_GL_POINT_SMOOTH)
92  ,m_GL_LINE_SMOOTH(a_from.m_GL_LINE_SMOOTH)
93  ,m_GL_BLEND(a_from.m_GL_BLEND)
94 
95  ,m_use_gsto(a_from.m_use_gsto)
96 
97  ,m_winding(a_from.m_winding)
98  ,m_color(a_from.m_color)
99  ,m_normal(a_from.m_normal)
100 
101  ,m_light(a_from.m_light)
102 
103  ,m_draw_type(a_from.m_draw_type)
104  ,m_shade_model(a_from.m_shade_model)
105 
106  ,m_line_width(a_from.m_line_width)
107  ,m_line_pattern(a_from.m_line_pattern)
108  ,m_point_size(a_from.m_point_size)
109 
110  ,m_camera_ortho(a_from.m_camera_ortho)
111  ,m_camera_znear(a_from.m_camera_znear)
112  ,m_camera_zfar(a_from.m_camera_zfar)
113  ,m_camera_position(a_from.m_camera_position)
114  ,m_camera_orientation(a_from.m_camera_orientation)
115  //,m_camera_near_height(a_from.m_camera_near_height)
116  ,m_camera_lrbt(a_from.m_camera_lrbt)
117  {
118 #ifdef TOOLS_MEM
119  mem::increment(s_class().c_str());
120 #endif
121  }

Member Function Documentation

◆ camera_proj_only()

void tools::sg::state::camera_proj_only ( mat4f a_mtx) const
inline

Definition at line 226 of file state.

226  {
227  float l = m_camera_lrbt[0];
228  float r = m_camera_lrbt[1];
229  float b = m_camera_lrbt[2];
230  float t = m_camera_lrbt[3];
231  float n = m_camera_znear;
232  float f = m_camera_zfar;
233  if(m_camera_ortho) {
234  a_mtx.set_ortho(l,r,b,t,n,f);
235  } else {
236  a_mtx.set_frustum(l,r,b,t,n,f);
237  }
238  }

◆ operator=()

state& tools::sg::state::operator= ( const state a_from)
inline

Definition at line 122 of file state.

122  {
123  m_ww = a_from.m_ww;
124  m_wh = a_from.m_wh;
125 
126  m_proj = a_from.m_proj;
127  m_model = a_from.m_model;
128 
129  m_GL_DEPTH_TEST = a_from.m_GL_DEPTH_TEST;
130  m_GL_LIGHTING = a_from.m_GL_LIGHTING;
131  m_GL_CULL_FACE = a_from.m_GL_CULL_FACE;
132  m_GL_POLYGON_OFFSET_FILL = a_from.m_GL_POLYGON_OFFSET_FILL;
133  m_GL_TEXTURE_2D = a_from.m_GL_TEXTURE_2D;
134  m_GL_POINT_SMOOTH = a_from.m_GL_POINT_SMOOTH;
135  m_GL_LINE_SMOOTH = a_from.m_GL_LINE_SMOOTH;
136  m_GL_BLEND = a_from.m_GL_BLEND;
137 
138  m_use_gsto = a_from.m_use_gsto;
139 
140  m_winding = a_from.m_winding;
141  m_color = a_from.m_color;
142  m_normal = a_from.m_normal;
143 
144  m_light = a_from.m_light;
145 
146  m_draw_type = a_from.m_draw_type;
147  m_shade_model = a_from.m_shade_model;
148 
149  m_line_width = a_from.m_line_width;
150  m_line_pattern = a_from.m_line_pattern;
151  m_point_size = a_from.m_point_size;
152 
153  m_camera_ortho = a_from.m_camera_ortho;
154  m_camera_znear = a_from.m_camera_znear;
155  m_camera_zfar = a_from.m_camera_zfar;
156  m_camera_position = a_from.m_camera_position;
157  m_camera_orientation = a_from.m_camera_orientation;
158  //m_camera_near_height = a_from.m_camera_near_height;
159  m_camera_lrbt = a_from.m_camera_lrbt;
160 
161  return *this;
162  }

◆ project_point()

bool tools::sg::state::project_point ( float &  a_x,
float &  a_y,
float &  a_z,
float &  a_w 
) const
inline

Definition at line 164 of file state.

164  {
165  a_w = 1;
166  m_model.mul_4f(a_x,a_y,a_z,a_w);
167  m_proj.mul_4f(a_x,a_y,a_z,a_w);
168  if(a_w==0.0F) return false;
169  a_x /= a_w;
170  a_y /= a_w;
171  a_z /= a_w;
172  return true;
173  }

◆ screen2ndc()

void tools::sg::state::screen2ndc ( int  a_x,
int  a_y,
float &  a_wcx,
float &  a_wcy,
float &  a_wcz,
float &  a_wcw 
) const
inline

Definition at line 175 of file state.

176  {
177  // a proj point in near plane has (z,w) :
178  // ortho -1,1 -> z/w = -1 and xy in [-1,1][-1,1]
179  // persp -n,n -> z/w = -1 and xy in [-n,n][-n,n]
180 
181  a_wcx = 2*(float(a_x)/float(m_ww)-0.5f); //in [-1,1]
182  a_wcy = 2*(float(a_y)/float(m_wh)-0.5f);
183  a_wcz = -1;
184 
185  if(m_camera_ortho) {
186  a_wcw = 1;
187  } else {
188  float t = m_camera_znear;
189  a_wcx *= t;
190  a_wcy *= t;
191  a_wcz *= t;
192  a_wcw = t;
193  }
194  }

◆ screen2pwc()

bool tools::sg::state::screen2pwc ( int  a_x,
int  a_y,
float &  a_wcx,
float &  a_wcy,
float &  a_wcz 
) const
inline

Definition at line 211 of file state.

212  {
213  mat4f mtx = m_proj;
214  //mtx.mul_mtx(m_model);
215  mat4f inv;
216  if(!mtx.invert(inv)) {a_wcx = 0;a_wcy = 0;a_wcz = 0;return false;}
217  float w;
218  screen2ndc(a_x,a_y,a_wcx,a_wcy,a_wcz,w);
219  inv.mul_4f(a_wcx,a_wcy,a_wcz,w);
220  if(w==0.0F) return false;
221  a_wcx /= w;
222  a_wcy /= w;
223  a_wcz /= w;
224  return true;
225  }

◆ screen2wc()

bool tools::sg::state::screen2wc ( int  a_x,
int  a_y,
float &  a_wcx,
float &  a_wcy,
float &  a_wcz 
) const
inline

Definition at line 196 of file state.

197  {
198  mat4f mtx = m_proj;
199  mtx.mul_mtx(m_model);
200  mat4f inv;
201  if(!mtx.invert(inv)) {a_wcx = 0;a_wcy = 0;a_wcz = 0;return false;}
202  float w;
203  screen2ndc(a_x,a_y,a_wcx,a_wcy,a_wcz,w);
204  inv.mul_4f(a_wcx,a_wcy,a_wcz,w);
205  if(w==0.0F) return false;
206  a_wcx /= w;
207  a_wcy /= w;
208  a_wcz /= w;
209  return true;
210  }

Member Data Documentation

◆ m_camera_lrbt

vec4f tools::sg::state::m_camera_lrbt

Definition at line 278 of file state.

◆ m_camera_orientation

rotf tools::sg::state::m_camera_orientation

Definition at line 276 of file state.

◆ m_camera_ortho

bool tools::sg::state::m_camera_ortho

Definition at line 272 of file state.

◆ m_camera_position

vec3f tools::sg::state::m_camera_position

Definition at line 275 of file state.

◆ m_camera_zfar

float tools::sg::state::m_camera_zfar

Definition at line 274 of file state.

◆ m_camera_znear

float tools::sg::state::m_camera_znear

Definition at line 273 of file state.

◆ m_color

colorf tools::sg::state::m_color

Definition at line 259 of file state.

◆ m_draw_type

draw_type tools::sg::state::m_draw_type

Definition at line 264 of file state.

◆ m_GL_BLEND

bool tools::sg::state::m_GL_BLEND

Definition at line 254 of file state.

◆ m_GL_CULL_FACE

bool tools::sg::state::m_GL_CULL_FACE

Definition at line 249 of file state.

◆ m_GL_DEPTH_TEST

bool tools::sg::state::m_GL_DEPTH_TEST

Definition at line 247 of file state.

◆ m_GL_LIGHTING

bool tools::sg::state::m_GL_LIGHTING

Definition at line 248 of file state.

◆ m_GL_LINE_SMOOTH

bool tools::sg::state::m_GL_LINE_SMOOTH

Definition at line 253 of file state.

◆ m_GL_POINT_SMOOTH

bool tools::sg::state::m_GL_POINT_SMOOTH

Definition at line 252 of file state.

◆ m_GL_POLYGON_OFFSET_FILL

bool tools::sg::state::m_GL_POLYGON_OFFSET_FILL

Definition at line 250 of file state.

◆ m_GL_TEXTURE_2D

bool tools::sg::state::m_GL_TEXTURE_2D

Definition at line 251 of file state.

◆ m_light

unsigned int tools::sg::state::m_light

Definition at line 262 of file state.

◆ m_line_pattern

unsigned short tools::sg::state::m_line_pattern

Definition at line 268 of file state.

◆ m_line_width

float tools::sg::state::m_line_width

Definition at line 267 of file state.

◆ m_model

mat4f tools::sg::state::m_model

Definition at line 245 of file state.

◆ m_normal

vec3f tools::sg::state::m_normal

Definition at line 260 of file state.

◆ m_point_size

float tools::sg::state::m_point_size

Definition at line 269 of file state.

◆ m_proj

mat4f tools::sg::state::m_proj

Definition at line 244 of file state.

◆ m_shade_model

shade_type tools::sg::state::m_shade_model

Definition at line 265 of file state.

◆ m_use_gsto

bool tools::sg::state::m_use_gsto

Definition at line 256 of file state.

◆ m_wh

unsigned int tools::sg::state::m_wh

Definition at line 242 of file state.

◆ m_winding

winding_type tools::sg::state::m_winding

Definition at line 258 of file state.

◆ m_ww

unsigned int tools::sg::state::m_ww

Definition at line 241 of file state.


The documentation for this class was generated from the following file:
tools::sg::state::m_GL_LIGHTING
bool m_GL_LIGHTING
Definition: state:248
tools::sg::state::m_GL_DEPTH_TEST
bool m_GL_DEPTH_TEST
Definition: state:247
tools::sg::winding_ccw
@ winding_ccw
Definition: enums:105
tools::sg::state::m_point_size
float m_point_size
Definition: state:269
tools::sg::state::m_GL_POLYGON_OFFSET_FILL
bool m_GL_POLYGON_OFFSET_FILL
Definition: state:250
tools::sg::shade_flat
@ shade_flat
Definition: enums:198
tools::sg::state::m_camera_znear
float m_camera_znear
Definition: state:273
tools::sg::state::m_GL_CULL_FACE
bool m_GL_CULL_FACE
Definition: state:249
tools::sg::state::m_normal
vec3f m_normal
Definition: state:260
tools::sg::state::m_winding
winding_type m_winding
Definition: state:258
tools::sg::state::m_camera_lrbt
vec4f m_camera_lrbt
Definition: state:278
tools::sg::state::m_GL_TEXTURE_2D
bool m_GL_TEXTURE_2D
Definition: state:251
tools::sg::state::m_GL_POINT_SMOOTH
bool m_GL_POINT_SMOOTH
Definition: state:252
tools::mat4f::mul_4f
void mul_4f(float &a_x, float &a_y, float &a_z, float &a_w) const
Definition: mat4f:61
tools::sg::state::m_camera_orientation
rotf m_camera_orientation
Definition: state:276
tools::sg::state::m_light
unsigned int m_light
Definition: state:262
tools::sg::state::m_wh
unsigned int m_wh
Definition: state:242
tools::sg::state::m_use_gsto
bool m_use_gsto
Definition: state:256
tools::sg::draw_filled
@ draw_filled
Definition: enums:193
tools::sg::state::m_camera_ortho
bool m_camera_ortho
Definition: state:272
tools::sg::state::m_GL_LINE_SMOOTH
bool m_GL_LINE_SMOOTH
Definition: state:253
tools::sg::state::m_camera_zfar
float m_camera_zfar
Definition: state:274
tools::sg::state::m_shade_model
shade_type m_shade_model
Definition: state:265
tools::sg::state::m_proj
mat4f m_proj
Definition: state:244
tools::sg::state::screen2ndc
void screen2ndc(int a_x, int a_y, float &a_wcx, float &a_wcy, float &a_wcz, float &a_wcw) const
Definition: state:175
tools::sg::state::m_model
mat4f m_model
Definition: state:245
tools::sg::state::m_ww
unsigned int m_ww
Definition: state:241
tools::sg::line_solid
@ line_solid
Definition: enums:11
tools::sg::state::m_camera_position
vec3f m_camera_position
Definition: state:275
tools::sg::state::m_line_pattern
unsigned short m_line_pattern
Definition: state:268
tools::sg::state::m_line_width
float m_line_width
Definition: state:267
tools::sg::state::m_color
colorf m_color
Definition: state:259
tools::sg::state::m_GL_BLEND
bool m_GL_BLEND
Definition: state:254
tools::sg::state::m_draw_type
draw_type m_draw_type
Definition: state:264