Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Animation blending testaus (OLD)
- * aseta idle weight 1.0, walk 0.0
- * kun painetaan up/down, lisää walk weightiä deltalla
- * jos ei paineta up/down, vähennä walk weight deltalla
- * ja walk pitää olla idlen JÄLKEEN eli mitä aikasempi animaatio,
- sitä vähemmäl se jää kun toiset animaatiot saa weightii (vissiin)
- Lataa ja käytä test_stickman.fbx_UkkoArmature* niin toimii oikein
- (test_stickman.fbx_Walk.ani:ssa animaatiossa ukko nytkähtää animaation lopussa, en tiedä miksi)
- */
- using Urho;
- using Urho.Samples;
- namespace AppUrhoGame1
- {
- public class Test_AnimationBlending_OLD : Sample
- {
- public Test_AnimationBlending_OLD(ApplicationOptions options = null) : base(options) { }
- bool drawDebug = false;
- Camera camera;
- Scene scene;
- CModel wall, floor;
- CAnimatedModel_OLD man;
- protected override void Start()
- {
- base.Start();
- CreateScene();
- }
- void CreateScene()
- {
- Globals.ResourceCache = ResourceCache;
- Globals.Graphics = Graphics;
- Globals.Input = Input;
- // 3D scene with Octree
- scene = new Scene(Context);
- scene.CreateComponent<Octree>();
- scene.CreateComponent<DebugRenderer>();
- // Create a directional light to the world. Enable cascaded shadows on it
- var lightNode = scene.CreateChild("DirectionalLight");
- lightNode.SetDirection(new Vector3(0.6f, -1.0f, 0.8f)); // The direction vector does not need to be normalized
- var light = lightNode.CreateComponent<Light>();
- light.LightType = LightType.Directional;
- light.CastShadows = true;
- light.ShadowBias = new BiasParameters(0.00025f, 0.5f);
- // Set cascade splits at 10, 50 and 200 world units, fade shadows out at 80% of maximum shadow distance
- light.ShadowCascade = new CascadeParameters(10.0f, 50.0f, 200.0f, 0.0f, 0.8f);
- // Create the camera. Limit far clip distance to match the fog
- CameraNode = scene.CreateChild("Camera");
- camera = CameraNode.CreateComponent<Camera>();
- camera.FarClip = 1000;
- CameraNode.Position = new Vector3(0.0f, 10.0f, -50.0f);
- Renderer.SetViewport(0, new Viewport(Context, scene, camera, null));
- //wall = CModel.Load(scene, "wall.fbx.mdl");
- //floor = CModel.Load(scene, "floor.fbx.mdl");
- //wall = CModel.Load(scene, "wall.fbx.mdl", "Material_001.xml");
- //floor = CModel.Load(scene, "floor.fbx.mdl", "Material.001.xml");
- const float SCALE = 20;
- for (int x = 0; x < 10; x++)
- {
- floor = CModel.Load(scene, "floor.fbx.mdl");
- floor.GetNode().SetTransform(new Vector3(x * SCALE, 0, 0), Quaternion.Identity, 1);
- wall = CModel.Load(scene, "wall.fbx.mdl");
- wall.GetNode().SetTransform(new Vector3(x * SCALE, 0, 0), Quaternion.Identity, 1);
- }
- man = CAnimatedModel_OLD.Load(scene, "test_stickman.fbx.mdl");
- man.LoadAnimation("test_stickman.fbx_UkkoArmatureIdle.ani", 1); // lataa ekana että walk weight muutos hävittää tämän
- man.LoadAnimation("test_stickman.fbx_UkkoArmatureWalk.ani", 0);
- }
- bool walk = false;
- protected override void OnUpdate(float timeStep)
- {
- base.OnUpdate(timeStep);
- SimpleMoveCamera3D(timeStep, 50);
- if (Input.GetKeyDown(Key.Tab))
- {
- drawDebug = !drawDebug;
- if (drawDebug) Renderer.DrawDebugGeometry(false);
- }
- walk = false;
- if (Input.GetKeyDown(Key.Up))
- {
- walk = true;
- man.GetNode().Translate(Vector3.Forward * timeStep * 5);
- }
- if (Input.GetKeyDown(Key.Down))
- {
- walk = true;
- man.GetNode().Translate(Vector3.Back * timeStep * 5);
- }
- if (Input.GetKeyDown(Key.Left))
- {
- man.GetNode().Rotate(new Quaternion(0, -timeStep * 200, 0), TransformSpace.Local);
- }
- if (Input.GetKeyDown(Key.Right))
- {
- man.GetNode().Rotate(new Quaternion(0, timeStep * 200, 0), TransformSpace.Local);
- }
- if (walk)
- {
- man.Update(1, timeStep);
- man.AddWeight(1, timeStep * 2.0f); // blendaa kävelyyn (muuta WALK animaation blendausta)
- }
- else
- {
- man.Update(0, timeStep * 0.2f); // idle
- man.AddWeight(1, -timeStep * 4.0f); // blendaa idleen (muuta WALK animaation blendausta)
- }
- /*
- // AMPUU KATSOMISSUUNTAAN:
- (aikash HACK, ei järkee laittaa dir varriin suuntaa, vaa laittais sen suoraan shootDir:iin)
- if (input->GetMouseButtonPress(MOUSEB_LEFT))
- {
- Vector3 dir = cameraNode_->GetRotation() * Vector3(0.0f, 0, 1.0f);
- obj->GetNode()->SetVar("dir", dir);
- obj->GetNode()->SetPosition(cameraNode_->GetPosition());
- }
- if (obj->GetNode()->GetVar("dir")!=0)
- {
- obj->GetNode()->Translate(obj->GetNode()->GetVar("dir").GetVector3() * 100 * timeStep);
- }
- *
- *
- * */
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement