Jelajahi Sumber

Demonstrate usage of spline interpolated animation, and set animation to node's world position(animation only attribute).

aster2013 11 tahun lalu
induk
melakukan
afaa9c7702

+ 22 - 16
Bin/Data/LuaScripts/30_LightAnimation.lua

@@ -44,29 +44,35 @@ function CreateScene()
     planeObject.model = cache:GetResource("Model", "Models/Plane.mdl")
     planeObject.material = cache:GetResource("Material", "Materials/StoneTiled.xml")
 
-    -- Create a directional light to the world so that we can see something. The light scene node's orientation controls the
-    -- light direction we will use the SetDirection() function which calculates the orientation from a forward direction vector.
-    -- The light will use default settings (white light, no shadows)
+    -- Create a point light to the world so that we can see something.
     local lightNode = scene_:CreateChild("DirectionalLight")
-    lightNode.direction = Vector3(0.6, -1.0, 0.8) -- The direction vector does not need to be normalized
     local light = lightNode:CreateComponent("Light")
-    light.lightType = LIGHT_DIRECTIONAL
+    light.lightType = LIGHT_POINT
+    light.range = 10.0
 
     -- Create light color animation
     local colorAnimation = AttributeAnimation:new()
-    local variant = Variant()
-    variant:SetColor(Color.WHITE)
-    colorAnimation:SetKeyFrame(0.0, variant)
-    variant:SetColor(Color.RED)
-    colorAnimation:SetKeyFrame(1.0, variant)
-    variant:SetColor(Color.YELLOW)
-    colorAnimation:SetKeyFrame(2.0, variant)
-    variant:SetColor(Color.GREEN)
-    colorAnimation:SetKeyFrame(3.0, variant)
-    variant:SetColor(Color.WHITE)
-    colorAnimation:SetKeyFrame(4.0, variant)
+    colorAnimation:SetKeyFrame(0.0, Variant(Color.WHITE))
+    colorAnimation:SetKeyFrame(1.0, Variant(Color.RED))
+    colorAnimation:SetKeyFrame(2.0, Variant(Color.YELLOW))
+    colorAnimation:SetKeyFrame(3.0, Variant(Color.GREEN))
+    colorAnimation:SetKeyFrame(4.0, Variant(Color.WHITE))
     light:SetAttributeAnimation("Color", colorAnimation)
 
+    -- Create light position animation
+    local positionAnimation = AttributeAnimation:new()
+    -- Use spline interpolation method
+    positionAnimation.interpolationMethod = IM_SPLINE
+    -- Set spline tension
+    positionAnimation.splineTension = 0.7
+    positionAnimation:SetKeyFrame(0.0, Variant(Vector3(-30.0, 5.0, -30.0)))
+    positionAnimation:SetKeyFrame(1.0, Variant(Vector3( 30.0, 5.0, -30.0)))
+    positionAnimation:SetKeyFrame(2.0, Variant(Vector3( 30.0, 5.0,  30.0)))
+    positionAnimation:SetKeyFrame(3.0, Variant(Vector3(-30.0, 5.0,  30.0)))
+    positionAnimation:SetKeyFrame(4.0, Variant(Vector3(-30.0, 5.0, -30.0)))
+    -- Set animation to node's world position
+    lightNode:SetAttributeAnimation("World Position", positionAnimation)
+
     -- Create more StaticModel objects to the scene, randomly positioned, rotated and scaled. For rotation, we construct a
     -- quaternion from Euler angles where the Y angle (rotation about the Y axis) is randomized. The mushroom model contains
     -- LOD levels, so the StaticModel component will automatically select the LOD level according to the view distance (you'll

+ 17 - 5
Bin/Data/Scripts/30_LightAnimation.as

@@ -46,13 +46,11 @@ void CreateScene()
     planeObject.model = cache.GetResource("Model", "Models/Plane.mdl");
     planeObject.material = cache.GetResource("Material", "Materials/StoneTiled.xml");
 
-    // Create a directional light to the world so that we can see something. The light scene node's orientation controls the
-    // light direction; we will use the SetDirection() function which calculates the orientation from a forward direction vector.
-    // The light will use default settings (white light, no shadows)
+    // Create a point light to the world so that we can see something.
     Node@ lightNode = scene_.CreateChild("DirectionalLight");
-    lightNode.direction = Vector3(0.6f, -1.0f, 0.8f); // The direction vector does not need to be normalized
     Light@ light = lightNode.CreateComponent("Light");
-    light.lightType = LIGHT_DIRECTIONAL;
+    light.lightType = LIGHT_POINT;
+    light.range = 10.0f;
 
     // Create light color animation
     AttributeAnimation@ colorAnimation = AttributeAnimation();
@@ -63,6 +61,20 @@ void CreateScene()
     colorAnimation.SetKeyFrame(4.0f, Variant(WHITE));
     light.SetAttributeAnimation("Color", colorAnimation);
 
+    // Create light position animation
+    AttributeAnimation@ positionAnimation = AttributeAnimation();
+    // Use spline interpolation method
+    positionAnimation.interpolationMethod = IM_SPLINE;
+    // Set spline tension
+    positionAnimation.splineTension = 0.7f;
+    positionAnimation.SetKeyFrame(0.0f, Variant(Vector3(-30.0f, 5.0f, -30.0f)));
+    positionAnimation.SetKeyFrame(1.0f, Variant(Vector3( 30.0f, 5.0f, -30.0f)));
+    positionAnimation.SetKeyFrame(2.0f, Variant(Vector3( 30.0f, 5.0f,  30.0f)));
+    positionAnimation.SetKeyFrame(3.0f, Variant(Vector3(-30.0f, 5.0f,  30.0f)));
+    positionAnimation.SetKeyFrame(4.0f, Variant(Vector3(-30.0f, 5.0f, -30.0f)));
+    // Set animation to node's world position
+    lightNode.SetAttributeAnimation("World Position", positionAnimation);
+
     // Create more StaticModel objects to the scene, randomly positioned, rotated and scaled. For rotation, we construct a
     // quaternion from Euler angles where the Y angle (rotation about the Y axis) is randomized. The mushroom model contains
     // LOD levels, so the StaticModel component will automatically select the LOD level according to the view distance (you'll

+ 19 - 7
Source/Samples/30_LightAnimation/LightAnimation.cpp

@@ -89,15 +89,13 @@ void LightAnimation::CreateScene()
     planeObject->SetModel(cache->GetResource<Model>("Models/Plane.mdl"));
     planeObject->SetMaterial(cache->GetResource<Material>("Materials/StoneTiled.xml"));
     
-    // Create a directional light to the world so that we can see something. The light scene node's orientation controls the
-    // light direction; we will use the SetDirection() function which calculates the orientation from a forward direction vector.
-    // The light will use default settings (white light, no shadows)
-    Node* lightNode = scene_->CreateChild("DirectionalLight");
-    lightNode->SetDirection(Vector3(0.6f, -1.0f, 0.8f)); // The direction vector does not need to be normalized
+    // Create a point light to the world so that we can see something. 
+    Node* lightNode = scene_->CreateChild("PointLight");
     Light* light = lightNode->CreateComponent<Light>();
-    light->SetLightType(LIGHT_DIRECTIONAL);
+    light->SetLightType(LIGHT_POINT);
+    light->SetRange(10.0f);
 
-    /// Create light color animation
+    // Create light color animation
     SharedPtr<AttributeAnimation> colorAnimation(new AttributeAnimation(context_));
     colorAnimation->SetKeyFrame(0.0f, Color::WHITE);
     colorAnimation->SetKeyFrame(1.0f, Color::RED);
@@ -106,6 +104,20 @@ void LightAnimation::CreateScene()
     colorAnimation->SetKeyFrame(4.0f, Color::WHITE);
     light->SetAttributeAnimation("Color", colorAnimation);
 
+    // Create light position animation
+    SharedPtr<AttributeAnimation> positionAnimation(new AttributeAnimation(context_));
+    // Use spline interpolation method
+    positionAnimation->SetInterpolationMethod(IM_SPLINE);
+    // Set spline tension
+    positionAnimation->SetSplineTension(0.7f);
+    positionAnimation->SetKeyFrame(0.0f, Vector3(-30.0f, 5.0f, -30.0f));
+    positionAnimation->SetKeyFrame(1.0f, Vector3( 30.0f, 5.0f, -30.0f));
+    positionAnimation->SetKeyFrame(2.0f, Vector3( 30.0f, 5.0f,  30.0f));
+    positionAnimation->SetKeyFrame(3.0f, Vector3(-30.0f, 5.0f,  30.0f));
+    positionAnimation->SetKeyFrame(4.0f, Vector3(-30.0f, 5.0f, -30.0f));
+    // Set animation to node's world position
+    lightNode->SetAttributeAnimation("World Position", positionAnimation);
+
     // Create more StaticModel objects to the scene, randomly positioned, rotated and scaled. For rotation, we construct a
     // quaternion from Euler angles where the Y angle (rotation about the Y axis) is randomized. The mushroom model contains
     // LOD levels, so the StaticModel component will automatically select the LOD level according to the view distance (you'll