INFO804 Introduction à l'informatique graphique
Loading...
Searching...
No Matches
Public Member Functions | Public Attributes | List of all members
rt::PointLight Struct Reference

#include <PointLight.h>

Inheritance diagram for rt::PointLight:
rt::Light

Public Member Functions

 PointLight (GLenum light_number, Point4 pos, Color emission_color, Color ambient_color=Color(0.0, 0.0, 0.0), Color diffuse_color=Color(1.0, 1.0, 1.0), Color specular_color=Color(1.0, 1.0, 1.0))
 
 ~PointLight ()
 Destructor.
 
void init (Viewer &viewer)
 
void light (Viewer &)
 
void draw (Viewer &viewer)
 
Vector3 direction (const Vector3 &p) const
 Given the point p, returns the normalized direction to this light.
 
Color color (const Vector3 &) const
 
- Public Member Functions inherited from rt::Light
 Light ()
 Default constructor. Nothing to do.
 
virtual ~Light ()
 Virtual destructor since object contains virtual methods.
 

Public Attributes

GLenum number
 Specifies which OpenGL light it is (necessary for draw())
 
Point4 position
 The position of the light in homogeneous coordinates.
 
Color emission
 The emission color of the light.
 
Material material
 The material (global to the light).
 
qglviewer::ManipulatedFrame * manipulator
 Used to store a manipulator to move the light in space.
 

Detailed Description

This structure defines a point light, which may be at an infinite distance. Such light does not suffer from any attenuation. One can also draw it in order to be displayed and manipulated.

Definition at line 19 of file PointLight.h.

Constructor & Destructor Documentation

◆ PointLight()

rt::PointLight::PointLight ( GLenum  light_number,
Point4  pos,
Color  emission_color,
Color  ambient_color = Color( 0.0, 0.0, 0.0 ),
Color  diffuse_color = Color( 1.0, 1.0, 1.0 ),
Color  specular_color = Color( 1.0, 1.0, 1.0 ) 
)
inline

Constructor. light_number must be different for every light (GL_LIGHT0, GL_LIGHT1, etc).

Definition at line 33 of file PointLight.h.

39 : number( light_number ), position( pos ), emission( emission_color ),
40 material( ambient_color, diffuse_color, specular_color ),
41 manipulator( 0 )
42 {}
GLenum number
Specifies which OpenGL light it is (necessary for draw())
Definition PointLight.h:21
qglviewer::ManipulatedFrame * manipulator
Used to store a manipulator to move the light in space.
Definition PointLight.h:29
Point4 position
The position of the light in homogeneous coordinates.
Definition PointLight.h:23
Color emission
The emission color of the light.
Definition PointLight.h:25
Material material
The material (global to the light).
Definition PointLight.h:27

◆ ~PointLight()

rt::PointLight::~PointLight ( )
inline

Destructor.

Definition at line 45 of file PointLight.h.

46 {
47 if ( manipulator != 0 ) delete manipulator;
48 }

Member Function Documentation

◆ color()

Color rt::PointLight::color ( const Vector3 ) const
inlinevirtual
Returns
the color of this light viewed from the given point p.

Implements rt::Light.

Definition at line 110 of file PointLight.h.

111 {
112 return emission;
113 }

◆ direction()

Vector3 rt::PointLight::direction ( const Vector3 p) const
inlinevirtual

Given the point p, returns the normalized direction to this light.

Implements rt::Light.

Definition at line 100 of file PointLight.h.

101 {
102 Vector3 pos( position.data() );
103 if ( position[ 3 ] == 0.0 ) return pos / pos.norm() ;
104 pos /= position[ 3 ];
105 pos -= p;
106 return pos / pos.norm();
107 }
PointVector< Real, 3 > Vector3
The type for representing a 3d point.

◆ draw()

void rt::PointLight::draw ( Viewer viewer)
inlinevirtual

This method is called by Scene::draw() at each frame to redisplay objects in the OpenGL window.

Implements rt::Light.

Definition at line 91 of file PointLight.h.

92 {
93 if ( manipulator != 0 && manipulator->grabsMouse() )
94 viewer.drawSomeLight( number, 1.2f );
95 else
96 viewer.drawSomeLight( number );
97 }

◆ init()

void rt::PointLight::init ( Viewer viewer)
inlinevirtual

This method is called by Scene::init() at the beginning of the display in the OpenGL window.

Implements rt::Light.

Definition at line 52 of file PointLight.h.

53 {
54 glMatrixMode(GL_MODELVIEW);
55 glLoadIdentity();
56 glEnable( number );
57 glLightfv( number, GL_AMBIENT, material.ambient );
58 glLightfv( number, GL_DIFFUSE, material.diffuse );
59 glLightfv( number, GL_SPECULAR, material.specular );
60 std::cout << "Init light at " << position << std::endl;
61 if ( position[ 3 ] != 0.0 ) // the point light is not at infinity
62 {
63 std::cout << "Init manipulator for light at " << position << std::endl;
64 manipulator = new qglviewer::ManipulatedFrame;
65 viewer.setMouseTracking( true );
66 manipulator->setPosition( position[ 0 ] / position[ 3 ],
67 position[ 1 ] / position[ 3 ],
68 position[ 2 ] / position[ 3 ] );
69 }
70 }
Color diffuse
diffuse color
Definition Material.h:22
Color ambient
ambient color
Definition Material.h:20
Color specular
specular color
Definition Material.h:24

◆ light()

void rt::PointLight::light ( Viewer )
inlinevirtual

This method is called by Scene::light() at each frame to set the lights in the OpenGL window.

Implements rt::Light.

Definition at line 74 of file PointLight.h.

75 {
76 Point4 pos = position;
77 if ( manipulator != 0 )
78 {
79 qglviewer::Vec pos2 = manipulator->position();
80 pos[0] = float(pos2.x);
81 pos[1] = float(pos2.y);
82 pos[2] = float(pos2.z);
83 pos[3] = 1.0f;
84 position = pos;
85 }
86 glLightfv( number, GL_POSITION, pos);
87 }

Member Data Documentation

◆ emission

Color rt::PointLight::emission

The emission color of the light.

Definition at line 25 of file PointLight.h.

◆ manipulator

qglviewer::ManipulatedFrame* rt::PointLight::manipulator

Used to store a manipulator to move the light in space.

Definition at line 29 of file PointLight.h.

◆ material

Material rt::PointLight::material

The material (global to the light).

Definition at line 27 of file PointLight.h.

◆ number

GLenum rt::PointLight::number

Specifies which OpenGL light it is (necessary for draw())

Definition at line 21 of file PointLight.h.

◆ position

Point4 rt::PointLight::position

The position of the light in homogeneous coordinates.

Definition at line 23 of file PointLight.h.


The documentation for this struct was generated from the following file: