MGCL V10  V10
MGCL V10
 全て クラス 名前空間 関数 変数 型定義 列挙型 列挙値 フレンド グループ ページ
Light.h
1 /********************************************************************/
2 /* Copyright (c) 2015 DG Technologies Inc. and Yuzi Mizuno */
3 /* All rights reserved. */
4 /********************************************************************/
5 #pragma once
6 
7 #ifndef _MGLIGHT_HH_
8 #define _MGLIGHT_HH_
9 
10 #include "mgGL/GLAttrib.h"
11 
12 class MGOfstream;
13 class MGIfstream;
14 class MGMatrix;
15 class MGSpotLight;
16 class MGDirectionalLight;
17 class MGPointLight;
18 
24 
27 class MG_DLL_DECLR MGLight:public MGGLAttrib{
28 
29 public:
30 
34  ON=1
35 };
36 
37 MG_DLL_DECLR friend std::ostream& operator<< (std::ostream&, const MGLight&);
38 
40 
41 MGLight();
42 MGLight(
43  float intensity,
44  float ambientIntensity,
45  const float color[3]
46 );
47 
49 
50 public:
51 
53 
55 virtual MGLight& operator=(const MGGel& gel2);
56 virtual MGLight& operator=(const MGLight& gel2);
57 
59 virtual bool operator<(const MGLight& gel2)const;
60 virtual bool operator<(const MGGel& gel2)const;
61 
63 virtual MGLight* clone()const;
64 
67 virtual int exec()const;
68 
69 static void ResetLight(GLint lightNo);
70 
72 virtual void drawAttrib(
73  mgVBO& vbo,
74  bool no_color=false
75 )const{exec();};
76 
78 GLenum get_light_num()const;
79 
82 bool light_is_on()const{return m_flag==ON;};
83 
85 virtual void render(mgVBO& vbo)const{exec();};
86 
88 virtual void set_draw_attrib_mask(unsigned int& mask)const{
89  set_Amask(mask,LIGHTING_BIT);
90 };
91 
93 void set_light_number(int lnum){m_lightNum=lnum;};
94 
96 virtual void reset_draw_attrib_mask(unsigned int& mask)const{
97  reset_Amask(mask,LIGHTING_BIT);
98 };
99 
101 virtual void set_render_attrib_mask(unsigned int& mask)const{set_Amask(mask,LIGHTING_BIT);};
102 
104 virtual void reset_render_attrib_mask(unsigned int& mask)const{reset_Amask(mask,LIGHTING_BIT);};
105 
107 
108 void setIntensity(float intensity){m_intensity=intensity;};
109 float getIntensity()const{return m_intensity;};
110 
111 void setAmbientIntensity(float ambientIntensity){
112  m_ambientIntensity=ambientIntensity;
113 };
114 float getAmbientIntensity()const{return m_ambientIntensity;};
115 
116 void setColor(const float color[3]){
117  for(int i=0;i<3; i++) m_color[i]=color[i];
118 };
119 void getColor(float color[3]){
120  for(int i=0;i<3; i++) color[i]=m_color[i];
121 };
122 void setColor(float v0, float v1, float v2){
123  m_color[0]=v0;
124  m_color[1]=v1;
125  m_color[2]=v2;
126 }
127 void getColor(float& v0, float& v1, float& v2){
128  v0=m_color[0];
129  v1=m_color[1];
130  v2=m_color[2];
131 }
132 
133 virtual std::string whoami()const{return "Light";};
134 
136 int turn_off();
137 
139 int turn_on();
140 
142 virtual void ReadMembers(MGIfstream& buf);
144 virtual void WriteMembers(MGOfstream& buf)const;
145 
147 virtual std::ostream& out(std::ostream&) const;
148 
149 protected:
150  unsigned int m_lightNum;
151  float m_intensity;
153  float m_color[3];
154 
156 MGLight& set_light(const MGLight& gel2);
157 
158 };
159  // end of GLAttrib group
161 #endif // _MGLIGHT_HH_
void reset_Amask(unsigned int &mask, MGGLAttrib::ATTRIB_MASK bit)
MGPointLight is a point light source that radiates equally in all directions.
Definition: PointLight.h:24
MGGLAttrib is an abstract class which defines the enum of undefined or disabled.
Definition: GLAttrib.h:35
void set_Amask(unsigned int &mask, MGGLAttrib::ATTRIB_MASK bit)
Set or reset the bit of mask.
Definition: GLAttrib.h:41
virtual bool operator<(const MGGel &gel2) const
LIGHT_MODE
Definition: Light.h:31
virtual MGGLAttrib * clone() const =0
Generate a newed clone object.
virtual void WriteMembers(MGOfstream &buf) const
Write all member data.
float m_ambientIntensity
applied to GL_AMBIENT
Definition: Light.h:152
virtual void ReadMembers(MGIfstream &buf)
Read all member data.
MGIfstream is a class to read the serialized data generated by MGOfstream.
Definition: Ifstream.h:30
virtual MGGLAttrib & operator=(const MGGLAttrib &gel2)
Definition: GLAttrib.h:70
void getColor(float &v0, float &v1, float &v2)
Definition: Light.h:127
Definition: GLAttrib.h:40
A directional light source.
Definition: SpotLight.h:22
virtual std::string whoami() const
Definition: Light.h:133
virtual void reset_render_attrib_mask(unsigned int &mask) const
Turn off the appropriate mask bit for this attribute. See glPushAttrib().
Definition: Light.h:104
MGLight is an abstract base class for light sources.
Definition: Light.h:27
virtual void render(mgVBO &vbo) const
render GLAttribute process.
Definition: Light.h:85
MGGel is an abstract class which represents a group element.
Definition: Gel.h:53
unsigned int m_lightNum
Definition: Light.h:150
virtual void set_draw_attrib_mask(unsigned int &mask) const
Turn on the appropriate mask bit for this attribute. See glPushAttrib().
Definition: Light.h:88
void setColor(const float color[3])
Definition: Light.h:116
float getIntensity() const
Definition: Light.h:109
float m_intensity
Color number of this light.
Definition: Light.h:151
virtual std::ostream & out(std::ostream &) const
Output virtual function.
MG_DLL_DECLR friend std::ostream & operator<<(std::ostream &ostrm, const MGGel &gel)
string stream function
MGOfstream is a class to serialize all of the subclasses of MGGel.
Definition: Ofstream.h:31
virtual void reset_draw_attrib_mask(unsigned int &mask) const
Turn off the appropriate mask bit for this attribute. See glPushAttrib().
Definition: Light.h:96
void set_light_number(int lnum)
Set light number.
Definition: Light.h:93
virtual void set_render_attrib_mask(unsigned int &mask) const
Turn on the appropriate mask bit for this attribute. See glPushAttrib().
Definition: Light.h:101
virtual void drawAttrib(mgVBO &vbo, bool no_color=false) const
draw GLAttribute process.
Definition: Light.h:72
void setColor(float v0, float v1, float v2)
Definition: Light.h:122
void setAmbientIntensity(float ambientIntensity)
Definition: Light.h:111
void setIntensity(float intensity)
Definition: Light.h:108
void getColor(float color[3])
Definition: Light.h:119
OpenGL 4 用描画のためのクラス, in other words, display list.
Definition: VBO.h:76
float getAmbientIntensity() const
Definition: Light.h:114
MGDirectionalLight is a directional light source that approximates infinite light sources as the sun...
Definition: DirectionalLight.h:25
bool light_is_on() const
Definition: Light.h:82
MGMatrix is a matix of m by m, where m is the space dimension.
Definition: Matrix.h:30