indexing description: "In this tutorial you will learn about scene nodes, actors, targets and how to use them" date: "$Date$" revision: "$Revision$" class NODE_SCENE inherit EM3D_SCENE rename make_scene as make redefine initialize_scene, handle_key_up_event end create make feature -- Init initialize_scene is -- Build your scene graph do precursor setup_camera setup_light setup_objects emgl_clear_color (0.1, 0.1,0.3,1) end setup_camera is -- Setup the camera position and target local -- A target is a special movable object that can be attach to any scene node -- Targets are used to describe points at which a camera or lightsource can point target: EM3D_TARGET do -- Create a new camera, ... active_camera := scene_manager.camera.create_new ( "MyCamera" ) -- ... attach it to a new scene node. camera_node := scene_manager.world.new_child_by_name ( "MyCamera position" ) camera_node.attach_object( active_camera ) -- Use the scene_manager to create a target, ... target := scene_manager.target.create_new_unnamed -- ... attach the target to a scene node, ... -- Option 1: You separate the target node from the camera, to have a fixed look at target_node := scene_manager.world.new_child_by_name ( "MyCamera target" ) -- Option 2: You make the target node as a child of the camera node, to have a local lookat (or lookat direction) -- target_node := camera_node.new_child_by_name ( "MyCamera target" ) target_node.attach_object( target ) -- ... and set the camera target. active_camera.set_target ( target ) -- Set the position of the two nodes camera_node.set_position ( [10, 0, 0] ) -- The up vector specifies which direction is up ( it specifies the Roll in Euler Angles ) active_camera.set_up ( [0,1,0] ) -- We want the upvector to be global active_camera.set_is_local_up ( false ) end target_node: EM3D_SCENE_NODE camera_node: EM3D_SCENE_NODE setup_objects is -- Load the objects, or just the monkey -- This part is covered by the 3D Object tutorial local object: EM3D_ACTOR do scene_manager.model_factory.load_model ( "data/monkey.x" ) object := scene_manager.model_factory.new_model ("data/monkey.x", scene_manager.world) end setup_light is -- In order to see some nice shading we need to setup some light -- To make things easy we reuse the camera target and position node local target: EM3D_TARGET light: EM3D_LIGHT do target := scene_manager.target.create_new_unnamed target_node.attach_object ( target ) -- In EM3D you have three types of lights light := scene_manager.light.create_new_directional_unnamed -- light := scene_manager.light.create_new_point_unnamed -- light := scene_manager.light.create_new_spot_unnamed -- You also need to attach a light to a scene node camera_node.attach_object ( light ) light.set_target ( target ) end handle_key_up_event( a_keyboard_event: EM_KEYBOARD_EVENT ) is -- Change the model when we press a key do if a_keyboard_event.key=a_keyboard_event.sdlk_escape then set_next_scene ( create {MAIN_SCENE}.make ) start_next_scene end end end