Class: GlimR::Material

Inherits:
SceneObject show all
Defined in:
lib/glimr/renderer/material.rb

Overview

A Material node controls OpenGL surface material parameters. It has accessors for ambient, diffuse, specular, shininess and emission.

Look up glMaterial and Blinn-Phong shading to find out more.

Instance Attribute Summary

Attributes inherited from SceneObject

#children, #drawables, #mtime, #parent, #viewport

Attributes included from EventListener

#event_listeners, #listener_count

Instance Method Summary collapse

Methods inherited from SceneObject

#<<, #absolute_geometry, #absolute_shader, #absolute_texture, #absolute_transform, #absolute_transform_for_drawing, #add_drawables, #attach, #clone, #default_config, #detach, #detach_self, #initialize, #inspect, #remove_drawables, #render, #replace_node, #root, #touch!, #visible

Methods included from Configurable

#default_config, #initialize

Methods included from EventListener

#add_event_listener, #decrement_listener_count, #dispatch_event, #event_root, #increment_listener_count, #initialize, #method_missing, #multicast_event, #process_event, #remove_event_listener

Constructor Details

This class inherits a constructor from GlimR::SceneObject

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class GlimR::EventListener

Instance Method Details

#absolute_materialObject

The absolute material of a Material is the parent’s absolute material merged with the Material.



18
19
20
21
22
23
24
25
26
27
28
# File 'lib/glimr/renderer/material.rb', line 18

def absolute_material
  @__pama ||= (
    pam = parent.absolute_material
    pam.ambient = ambient if ambient
    pam.diffuse = diffuse if diffuse
    pam.specular = specular if specular
    pam.shininess = shininess if shininess
    pam.emission = emission if emission
    pam
  )
end

#applyObject

Applies the material by calling GL::Material to set the material properties.



31
32
33
34
35
36
37
# File 'lib/glimr/renderer/material.rb', line 31

def apply
  Material(FRONT_AND_BACK, AMBIENT, ambient) if ambient
  Material(FRONT_AND_BACK, DIFFUSE, diffuse) if diffuse
  Material(FRONT_AND_BACK, SPECULAR, specular) if specular
  Material(FRONT_AND_BACK, SHININESS, shininess) if shininess
  Material(FRONT_AND_BACK, EMISSION, emission) if emission
end

#pop_stateObject

Pops the attrib stack.



45
46
47
# File 'lib/glimr/renderer/material.rb', line 45

def pop_state
  PopAttrib()
end

#push_stateObject

Pushes the LIGHTING_BIT to attrib stack.



40
41
42
# File 'lib/glimr/renderer/material.rb', line 40

def push_state
  PushAttrib(LIGHTING_BIT)
end

#replace!(other) ⇒ Object

Replaces the instance variables of the Material with the other’s.



51
52
53
54
55
56
57
58
# File 'lib/glimr/renderer/material.rb', line 51

def replace!(other)
  @ambient = other.ambient
  @diffuse = other.diffuse
  @specular = other.specular
  @shininess = other.shininess
  @emission = other.emission
  self
end