Add attribute animation sample in StaticScene.

This commit is contained in:
aster2013 2014-03-22 22:53:01 +08:00
parent 2eff0e1144
commit da7936dd68

View File

@ -21,6 +21,7 @@
//
#include "Camera.h"
#include "AttributeAnimation.h"
#include "CoreEvents.h"
#include "Engine.h"
#include "Font.h"
@ -39,6 +40,7 @@
#include "StaticScene.h"
#include "DebugNew.h"
#include "Animatable.h"
DEFINE_APPLICATION_MAIN(StaticScene)
@ -95,7 +97,17 @@ void StaticScene::CreateScene()
lightNode->SetDirection(Vector3(0.6f, -1.0f, 0.8f)); // The direction vector does not need to be normalized
Light* light = lightNode->CreateComponent<Light>();
light->SetLightType(LIGHT_DIRECTIONAL);
/// Create light color animation
SharedPtr<AttributeAnimation> colorAnimation(new AttributeAnimation(context_));
colorAnimation->SetValueType(VAR_COLOR);
colorAnimation->AddKeyFrame(0.0f, Color::WHITE);
colorAnimation->AddKeyFrame(1.0f, Color::RED);
colorAnimation->AddKeyFrame(2.0f, Color::YELLOW);
colorAnimation->AddKeyFrame(3.0f, Color::GREEN);
colorAnimation->AddKeyFrame(4.0f, Color::WHITE);
light->SetAttributeAnimation("Color", colorAnimation);
// 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
@ -106,12 +118,23 @@ void StaticScene::CreateScene()
for (unsigned i = 0; i < NUM_OBJECTS; ++i)
{
Node* mushroomNode = scene_->CreateChild("Mushroom");
mushroomNode->SetPosition(Vector3(Random(90.0f) - 45.0f, 0.0f, Random(90.0f) - 45.0f));
Vector3 position(Random(90.0f) - 45.0f, 0.0f, Random(90.0f) - 45.0f);
mushroomNode->SetPosition(position);
mushroomNode->SetRotation(Quaternion(0.0f, Random(360.0f), 0.0f));
mushroomNode->SetScale(0.5f + Random(2.0f));
StaticModel* mushroomObject = mushroomNode->CreateComponent<StaticModel>();
mushroomObject->SetModel(cache->GetResource<Model>("Models/Mushroom.mdl"));
mushroomObject->SetMaterial(cache->GetResource<Material>("Materials/Mushroom.xml"));
/// Create mushroom position animation.
SharedPtr<AttributeAnimation> positionAnimaiton(new AttributeAnimation(context_));
positionAnimaiton->SetValueType(VAR_VECTOR3);
positionAnimaiton->AddKeyFrame(0.0f, position);
positionAnimaiton->AddKeyFrame(1.0f, position + Vector3(Random(2.0f) - 1.0f, 0.0f, Random(2.0f) - 1.0f));
positionAnimaiton->AddKeyFrame(2.0f, position + Vector3(Random(2.0f) - 1.0f, 0.0f, Random(2.0f) - 1.0f));
positionAnimaiton->AddKeyFrame(3.0f, position);
mushroomNode->SetAttributeAnimation("Position", positionAnimaiton);
}
// Create a scene node for the camera, which we will move around