#!/usr/bin/ruby -w require 'application' include Ogre $animation_state_list = [] class LightingListener < ApplicationFrameListener def frame_started(event) return false unless super(event) $animation_state_list.each do |anim| anim.add_time(event.time_since_last_frame) end true end end class LightingApplication < Application def create_scene scene_manager.set_ambient_light ColourValue.new(0.5, 0.5, 0.5) scene_manager.set_sky_box(true, "SpaceSkyBox") head = scene_manager.create_entity("head", "ogrehead.mesh") scene_manager.root_scene_node.attach_object(head) ## Set up light ribbons dir = Vector3.new(-1, -1, 0.5) dir.normalise! l = scene_manager.create_light("light1") l.set_type Light::LT_DIRECTIONAL l.set_direction dir trail = scene_manager.create_movable_object("RibbonTrail1", "RibbonTrail", {"numberOfChains" => "2", "maxElements" => "80"}) trail.set_material_name "LightRibbonTrail" trail.set_trail_length 400 puts trail scene_manager.root_scene_node.create_child_scene_node.attach_object(trail) anim_node = scene_manager.root_scene_node.create_child_scene_node anim_node.set_position Vector3.new(50,30,0) anim = scene_manager.create_animation("an1", 14) anim.set_interpolation_mode Animation::IM_SPLINE track = anim.create_node_track(1, anim_node) kf = track.create_node_key_frame(0) kf.set_translate Vector3.new(50,30,0) kf = track.create_node_key_frame(2) kf.set_translate Vector3.new(100, -30, 0) kf = track.create_node_key_frame(4) kf.set_translate Vector3.new(120, -100, 150) kf = track.create_node_key_frame(6) kf.set_translate Vector3.new(30, -100, 50) kf = track.create_node_key_frame(8) kf.set_translate Vector3.new(-50, 30, -50) kf = track.create_node_key_frame(10) kf.set_translate Vector3.new(-150, -20, -100) kf = track.create_node_key_frame(12) kf.set_translate Vector3.new(-50, -30, 0) kf = track.create_node_key_frame(14) kf.set_translate Vector3.new(50,30,0) anim_state = scene_manager.create_animation_state("an1") anim_state.set_enabled true $animation_state_list << anim_state trail.set_initial_colour(0, 1.0, 0.8, 0) trail.set_colour_change(0, 0.5, 0.5, 0.5, 0.5) trail.set_initial_width(0, 5) trail.add_node(anim_node) # Add light l2 = scene_manager.create_light("l2") l2.set_diffuse_colour trail.get_initial_colour(0) anim_node.attach_object(l2) # Add billboard bbs = scene_manager.create_billboard_set("bb", 1) bbs.create_billboard(Vector3.ZERO, trail.get_initial_colour(0)) bbs.set_material_name "Flare" anim_node.attach_object(bbs) anim_node = scene_manager.root_scene_node.create_child_scene_node anim_node.set_position Vector3.new(-50,100,0) anim = scene_manager.create_animation("an2", 10) anim.set_interpolation_mode Animation::IM_SPLINE track = anim.create_node_track(1, anim_node) kf = track.create_node_key_frame(0) kf.set_translate Vector3.new(-50,100,0) kf = track.create_node_key_frame(2) kf.set_translate Vector3.new(-100, 150, -30) kf = track.create_node_key_frame(4) kf.set_translate Vector3.new(-200, 0, 40) kf = track.create_node_key_frame(6) kf.set_translate Vector3.new(0, -150, 70) kf = track.create_node_key_frame(8) kf.set_translate Vector3.new(50, 0, 30) kf = track.create_node_key_frame(10) kf.set_translate Vector3.new(-50,100,0) anim_state = scene_manager.create_animation_state("an2") anim_state.set_enabled true $animation_state_list << anim_state trail.set_initial_colour(1, 0.0, 1.0, 0.4) trail.set_colour_change(1, 0.5, 0.5, 0.5, 0.5) trail.set_initial_width(1, 5) trail.add_node(anim_node) # Add light l2 = scene_manager.create_light("l3") l2.set_diffuse_colour trail.get_initial_colour(1) anim_node.attach_object(l2) # Add billboard bbs = scene_manager.create_billboard_set("bb2", 1) bbs.create_billboard(Vector3.ZERO, trail.get_initial_colour(1)) bbs.set_material_name "Flare" anim_node.attach_object(bbs) end def create_frame_listener self.frame_listener = LightingListener.new(root, window, camera) #root.addFrameListener(self.frame_listener) end end app = LightingApplication.new app.go