Animation in Minecraft Movement within Movement Copyright © 2015 – Curt Hill.

Slides:



Advertisements
Similar presentations
AP Computer Science Anthony Keen. Computer 101 What happens when you turn a computer on? –BIOS tries to start a system loader –A system loader tries to.
Advertisements

Introduction to Algorithms Quicksort
Review of Chapter 4 Sections 1 and 2 World-level methods involve two or more objects break a large problem into smaller, logical units follow a design.
Copyright 2003Curt Hill Hash indexes Are they better or worse than a B+Tree?
JavaScript Part for Repetition Statement for statement Cpecifies each of the items needed for counter-controlled repetition with a control variable.
Slides prepared by Rose Williams, Binghamton University ICS201 Lectures 18 : Threads King Fahd University of Petroleum & Minerals College of Computer Science.
Chapter 5 - Arrays CSC 200 Matt Kayala 2/27/06. Learning Objectives  Introduction to Arrays  Declaring and referencing arrays  For-loops and arrays.
CS 106 Introduction to Computer Science I 04 / 21 / 2008 Instructor: Michael Eckmann.
Slides prepared by Rose Williams, Binghamton University Chapter 16 Collections and Iterators.
Chapter 9 Introduction to Arrays
CS 106 Introduction to Computer Science I 04 / 28 / 2010 Instructor: Michael Eckmann.
CMSC 202 Interfaces. 11/20102 Classes and Methods When a class defines its methods as public, it describes how the class user interacts with the method.
Programming with Alice Computing Institute for K-12 Teachers Summer 2011 Workshop.
Copyright © 2015 – Curt Hill Minecraft Blocks Properties and Methods.
CS 106 Introduction to Computer Science I 03 / 19 / 2007 Instructor: Michael Eckmann.
COMPUTER PROGRAMMING. Control Structures A program is usually not limited to a linear sequence of instructions. During its process it may repeat code.
Method Overriding Remember inheritance: when a child class inherits methods, variables, etc from a parent class. Example: public class Dictionary extends.
Copyright © 2015 Curt Hill Models and Textures Making your entity interesting.
Arrays Module 6. Objectives Nature and purpose of an array Using arrays in Java programs Methods with array parameter Methods that return an array Array.
Java Threads. What is a Thread? A thread can be loosely defined as a separate stream of execution that takes place simultaneously with and independently.
 Definition: The ability to derive child classes (sub- classes) from parent classes (super-classes)  Characteristics:  Methods and instance variables.
Copyright © Curt Hill Generic Classes Template Classes or Container Classes.
CS 106 Introduction to Computer Science I 04 / 23 / 2010 Instructor: Michael Eckmann.
OBJECTS FOR ORGANIZING DATA -- As our programs get more sophisticated, we need assistance organizing large amounts of data. : array declaration and use.
Introduction to Java Java Translation Program Structure
Copyright Curt Hill Variables What are they? Why do we need them?
Copyright © Curt Hill More Components Varying the input of Dev-C++ Windows Programs.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 2: Methods and Data Programming with Alice and Java First Edition.
Copyright © 2015 Curt Hill Java for Minecraft Those things you should know.
Copyright © – Curt Hill Pointers A Light Introduction.
1 CS 177 Week 11 Recitation Slides Class Design/Custom Classes.
Slide 1 Chapter 5 Arrays. Slide 2 Learning Objectives  Introduction to Arrays  Declaring and referencing arrays  For-loops and arrays  Arrays in memory.
Chapter 5 Arrays. Copyright © 2006 Pearson Addison-Wesley. All rights reserved. 5-2 Learning Objectives  Introduction to Arrays  Declaring and referencing.
Final Review. From ArrayLists to Arrays The ArrayList : used to organize a list of objects –It is a class in the Java API –the ArrayList class uses an.
Copyright Curt Hill Arrays in C/C++ More on usage.
Copyright © Curt Hill Formatting Reals Outputs other than normal.
The Math Class Methods Utilizing the Important Math Operations of Java!
CS1101 Group1 Discussion 10 Lek Hsiang Hui comp.nus.edu.sg
 In the java programming language, a keyword is one of 50 reserved words which have a predefined meaning in the language; because of this,
Copyright © Curt Hill Error Handling in Java Throwing and catching exceptions.
Lecture 8: Advanced OOP Part 2. Overview Review of Subtypes Interfaces Packages Sorting.
Classes, Interfaces and Packages
Slides prepared by Rose Williams, Binghamton University Chapter 16 Collections and Iterators.
Recipes How to craft items from others Copyright © 2015 Curt Hill.
Fortran: Control Structures Session Three ICoCSIS.
Copyright © Curt Hill Flow of Control A Quick Overview.
Copyright © Curt Hill More on Operating Systems Continuation of Introduction.
Chapter 5 Arrays Copyright © 2016 Pearson, Inc. All rights reserved.
Chapter 9 Introduction to Arrays Fundamentals of Java.
Introduction to Exceptions in Java CS201, SW Development Methods.
Chapter 4 - Finishing the Crab Game
A Review or Brief Introduction
Putting Objects in Motion
Atomic Operations in Hardware
The for-each or for-all loop introduced in Java 5
Chapter 19 Java Never Ends
Java Programming: Guided Learning with Early Objects
Organizing common actions
A brief look at some of the new features introduced to the language
Doing things more than once
Arrays in Java What, why and how Copyright Curt Hill.
Throwing and catching exceptions
The Diamond Problem Its Solution Copyright © 2017 Curt Hill.
Other displays Saving Arrays Using fors to process
Examining Variables on Flow Paths
Focus of the Course Object-Oriented Software Development
The Java switch Statement
Dr. Sampath Jayarathna Cal Poly Pomona
Classes, Objects and Methods
Methods Scope How are names handled?
Presentation transcript:

Animation in Minecraft Movement within Movement Copyright © 2015 – Curt Hill

Introduction If we created an entity that was a derivation of EntityCreature it will move –This is part of its inherited behavior –It will move in a semi-random fashion If it is modeled with multiple boxes it will move in an unrealistic fashion –It will look like the figure is frozen in a block of ice and the block is drug around Now we set out to fix this

The Modeler The derivation of ModelBase contains a render method In the example this class is CurtModelEmu All the animation work is done in this method or the methods it calls The movements we apply here are strictly ornamental –They just make things more realistic Copyright © 2015 – Curt Hill

The render method This is called multiple times a second The parent piece is moved by Minecraft We use this method to move appendages Not so much move as rotate them on the body or to whatever they are attached Copyright © 2015 – Curt Hill

Angles There are three angle properties in ModelRenderer –Recall that each box is an object of this type rotateAngleX, rotateAngleY and rotateAngleZ These determine the angles of the box –For the parent this is relative to the coordinate system –For children this is relative to the parent and attachment point Copyright © 2015 – Curt Hill

Interlude on Angles Most of us are used to measuring angles in degrees Java only believes in radians for measuring angles –Java follows mathematics and science in this belief There are 2π radians in 360° A good article as to why radians are superior is: Copyright © 2015 – Curt Hill

Table Copyright © 2015 – Curt Hill DegreesRadians

Angles Again Like a good mathematician I will only use radians in code and examples If you are stuck in bad practice use this conversion function: float degToRad(float deg){ return deg*(float)Math.PI/180; } Copyright © 2015 – Curt Hill

The rotates Each of the rotateAngle variables take radians They set the box to that angle immediately Typically you wish to avoid large angular changes Moreover, you also need to be sensitive to motion of the entity Copyright © 2015 – Curt Hill

Disjointed Action An appendage rotating has to occur over a time period Thus each call to render moves it some distance but not usually the total distance We also need to keep track of progress There are several practical techniques that we can use Copyright © 2015 – Curt Hill

A Counter We need a counter that tells which visit to render we are currently in This is usually an instance variable of the class –May also be a static local variable of render Each call to render we increment it We want this value to be in some range which is usually less than 50 –We either divide and keep remainder or zero it periodically Copyright © 2015 – Curt Hill

Selective Actions Once the counter is set and in the right range, how do we use it? Two good ways: –Use as an index in a constant array to store the values –Use as the selector in a switch case Lets turn the emu’s head in both ways Copyright © 2015 – Curt Hill

The Counter in Modeler Copyright © 2015 – Curt public class CurtModelEmu extends ModelBase{ public ModelRenderer body; public ModelRenderer leg1; public ModelRenderer leg2; public ModelRenderer neck; public ModelRenderer head; protected int headCycle=0;

The renderEmu Copyright © 2015 – Curt Hill public void renderEmu( CurtEmu ent, float time, float swingSuppress, float par4, float headAngleY, float headAngleX, float par7) { setRotationAngles(time, swingSuppress, par4, headAngleY, headAngleX, par7, ent); body.render(par7); }

Comments The above two methods will be the same for both approaches Notice that we set the angles Then we render the body Since the body is the parent, all the children will also be rendered The renderEmu routine gets all the parameters, but I will not use any of them, nor show them here Next two versions of renderEmu Copyright © 2015 – Curt Hill

Using a Switch Copyright © 2015 – Curt public void setRotationAngles(…){ switch (headCycle++%20) case 3: head.rotateAngleY =.2F; break; case 4: head.rotateAngleY =.4F; break; case 5: head.rotateAngleY =.5f; break; …

Array Copyright © 2015 – Curt Hill float turns[] = new float[]{0f, 0f, 0f,.2f,.4f,.5f,.5f,.4f,.2f, 0f,0f,-.2f,-.4f,-.5f,-.5f, -.4f, -.2f, 0f,0f, 0f,0f,0f}; public void setRotationAngles(…){ head.rotateAngleY = turns[headCycle++%20]; }

Comparison The switch is much more code In the array fill in gaps that the switch does not Also beware of subscripting errors Once the basic approach is set, it is easy to make it faster or slower or make the rotation greater or lesser Copyright © 2015 – Curt Hill

Motion The emu moves its head all the time However, you do not want the legs to walk when the emu is standing still How do we detect motion? Copyright © 2015 – Curt Hill

Entities Again Entities have several properties of value here posX, prevPosX and the corresponding Y and Z items Comparing current and previous for X and Z will tell if this item is moving in the plane or not –Changing Y would be a jump We can then test the current and previous and only animate if there is motion Copyright © 2015 – Curt Hill

Head wagging All the suggestions so far given are synchronous All the emus will wag their heads at the same time –Looks unnatural –Not really a problem with walking We can vary this by introducing some randomness Insert a random object and cancel occasional ticks before the wag Copyright © 2015 – Curt Hill

The Final Routines In the following screens are the final animations produced in this presentation Copyright © 2015 – Curt Hill

setRotationAngles Copyright © 2015 – Curt public void setRotationAngles(…){ setHeadAngle(); setLegAngles(ent); }

setHeadAngle Copyright © 2015 – Curt Hill protected void setHeadAngle(){ if(headCycle%20 < 3){ int r = rand.nextInt(10); if(r<6){ headCycle = 0; return; } head.rotateAngleY = turns[headCycle++%20]; }

setLegAngles Copyright © 2015 – Curt Hill protected void setLegAngles (Entity ent){ if(ent.prevPosX==ent.posX && ent.prevPosZ==ent.posZ){ // no motion leg1.rotateAngleX = 0f; leg2.rotateAngleX = 0f; legCycle = 0; } else { leg1.rotateAngleX = walks[legCycle++%11]; leg2.rotateAngleX = -leg1.rotateAngleX; }

Concussion Now we are ready to create harmless entities Helping non-harmless entities to attack or flee must await the next presentation Copyright © 2015 – Curt Hill