SlideShare a Scribd company logo
   What is animation
   Attributes can be varied
    ›   Position
    ›   Velocity
    ›   Accelration
    ›   Width, height
    ›   Rotation
    ›   Alpha
    ›   Time interval
    ›   Color
   Easing
   Bounce
   Spring
   Tweener
    ›   Performance issue
   Creating Curve / Shapes / Volume
    ›   Application of curve
   Using Vector
    ›   Optimizing ball collision demo
   What is animation?

    › Particle System Demo
   Change of Object’s Properties over time

    › What properties to change?


    › What objects to apply?


    › How to trigger the animation?
Visible properties                Invisible properties
Position                          Velocity


Scale                             Angular Velocity
(width and height)
Rotation                          Acceleration
Alpha                             Angular Acceleration
Color                             Loop interval
(brightness, saturation, tone…)
Depth                             Sound Volume
Appearance
(e.g. blur filter, shape)
 Movieclips
 Text Box
 Sound Object
 Camera (in 3D application)
   Static animation
    › Timeline
    › Pre-programmed animation


   Dynamic animation
    › Mouse actions
    › Keyboard actions
    › Web Cam (Augmented Reality)
    › Microphone
Initialization

                  Animation
                    Loop
 Update
properties

                 No
Animation
 Ended?

    Yes

Animation
 Ended
   We will go through…
    › Velocity
    › Acceleration
    › Friction
    › Boundaries
    › Easing and Springing
    › Angular Motion
    › Collision Detection
    › Frame-based VS Time-based
   Velocity
    › Rate of change of position over time


   Acceleration
    › Rate of change of velocity over time


   Useful formulae
    vx = vx + ax,   vy = vy + ay

     x = x + vx,    y = y + vy
   There can be energy loss when an
    object moves

    › Causing the object to slow down


   An easy way to implement friction:
    vx *= friction factor
    vy *= friction factor

    where friction factor is from 0 to 1
   The previous method is only an approximation
    because:
     › In real physics, friction of a moving object has
       no relationship on velocity

   Real Physics (acceleration = -0.2)
     t     0     1     2      3      4       5
     v     10    8     6      4      2       0

   Approximation (friction factor = 0.3):
     t     0     1     2      3      4       5
     v     10    4     1.6    0.64   0.256   0.1024
   However, with the previous method:
    › Normal user should not be able to discover
    › No change of the sign of velocity
       Write less “if then else” statements in code

   The correct method:
    var speed:Number = Math.sqrt(vx * vx + vy * vy);
    var angle:Number = Math.atan2(vy, vx);
    if (speed > friction) {
               speed -= friction;
    }
    else {
               speed = 0;
    }
    vx = Math.cos(angle) * speed;
    vy = Math.sin(angle) * speed;
   Bouncing




    If (ball.x + ball.width / 2 > right || ball.x – ball.width / 2 < left) {
                 ball.vx = -ball.vx;
    }

    If (ball.y + ball.height / 2 > bottom || ball.y – ball.height / 2 < top) {
                 ball.vy = -ball.vy;
    }
   Bouncing with energy loss                                                  Without Energy loss



                                                                                        With Energy loss




    If (ball.x + ball.width / 2 > right || ball.x – ball.width / 2 < left) {
                 ball.vx = -ball.vx * friction;
    }

    If (ball.y + ball.height / 2 > bottom || ball.y – ball.height / 2 < top) {
                 ball.vy = -ball.vy * friction;
    }
   Screen wrapping




                      Re-appear in the
                      other side!
If (ball.x - ball.width / 2 > right ) {
              ball.x = left – ball.width / 2;
}
else if (ball.x _+ ball.width / 2 < left) {
              ball.x = right + ball.width / 2;
}

If (ball.y - ball.height / 2 > bottom) {
              ball.y = top – ball.height / 2;
}
else if (ball.y _+ ball.height / 2 < top) {
              ball.y = bottom + ball.height / 2;
}
   Demo showing
    › Friction
    › Boundary
    › Energy loss hitting wall
    › throwing
 Velocity is proportional to target distance
 Object moves smoothly and decelerate to the
  target position
displacement


    Target pos




                                       time
   Formula for easing

    x += (targetX – x) * easingFactor;;
    y += (targetY – y) * easingFactor;;
 Acceleration is proportional to target distance
 Objects move smoothly, vibrate and then slow
  down through the target position
displacement


    Target pos




                                           time
   Formula for springing
    vx += (targetX – x) * springFactor;
    vy += (targetY – y) * springFactor;

    //add friction, otherwise the object will never stop
    vx *= frictionFactor;
    vy *= frictionFactor;

    x += vx;
    y += vy;
   In real world,
     › Objects usually move along an arced trajectory
     › Objects usually accelerates when start and
        decelerate when stop
     › This kind of motion create “natural” feeling to us
     › Easing is used entired in Mac OS / iPhone!
   Tweener is a well-known Flash tweening library
    http://code.google.com/p/tweener/

   Easing can be done in just 1 statement
     › Can you read the meaning below?
    Tweener.addTween(this.ball, {
          x: 100,
          alpha: 0,
          time: 2,
          delay: 1,
          transition: easeOutExpo
    });
   Some famous tweening libraries
    ›   Tweener
    ›   TweenLite
    ›   Boostworthy Animation System
    ›   FuseKit
    ›   Go
    ›   KitchenSync

   A comparison of these tweening libraries can
    be found at:
    http://dispatchevent.org/wp-
    content/uploads/2008/04/Tween-Engine-
    Comparisons.pdf
   Think in polar co-ordinate and then
    transform into the Cartesian Plane

                        (x,y)   x = r * Math.cos(θ);
                r               y = r * Math.sin(θ);
                    θ
   Angular Velocity
    › Rate of change of θ over time


   Angular Acceleration
    › Rate of change of angular velocity over time

 Angular Friction
 Angular easing
 Angular Springing
   Sine curve

   Circle
   First person shooter game
    › Move up and down when walk


   Biased Value Mapping
    › Random number biasing
    › My Website’s wallpaper rotator
   Rectangular Plane

   Circular Plane

   Cylinder

   Cone

   Helix

   Sphere
 Make code simpler
 Same thinking in 2D and 3D space
 Add
 Subtraction
 Scale
 Dot production
 Normalize
 Get Length
   Collision Detection of a group of sphere

   Explosion Effect in 3D space

More Related Content

Similar to Animation programming

Projectile motion ch 5 reg
Projectile motion ch 5 regProjectile motion ch 5 reg
Projectile motion ch 5 reg
ZBTHS
 
Physics - Chapter 2 - One Dimensional Motion
Physics - Chapter 2 - One Dimensional MotionPhysics - Chapter 2 - One Dimensional Motion
Physics - Chapter 2 - One Dimensional Motion
JPoilek
 
Chapter2powerpoint 090816163937-phpapp02
Chapter2powerpoint 090816163937-phpapp02Chapter2powerpoint 090816163937-phpapp02
Chapter2powerpoint 090816163937-phpapp02
Cleophas Rwemera
 
Free fall PHYSICS IGCSE FORM 3 MRSM
Free fall PHYSICS IGCSE  FORM 3 MRSMFree fall PHYSICS IGCSE  FORM 3 MRSM
Free fall PHYSICS IGCSE FORM 3 MRSM
Nurul Fadhilah
 
Intro to Game Programming
Intro to Game ProgrammingIntro to Game Programming
Intro to Game Programming
Richard Jones
 
Introduction to Canvas - Toronto HTML5 User Group
Introduction to Canvas - Toronto HTML5 User GroupIntroduction to Canvas - Toronto HTML5 User Group
Introduction to Canvas - Toronto HTML5 User Group
dreambreeze
 
Introduction to Canvas - Toronto HTML5 User Group
Introduction to Canvas - Toronto HTML5 User GroupIntroduction to Canvas - Toronto HTML5 User Group
Introduction to Canvas - Toronto HTML5 User Group
bernice-chan
 
3 d transformation
3 d transformation3 d transformation
3 d transformation
Mani Kanth
 
Intro to Canva
Intro to CanvaIntro to Canva
Intro to Canva
dreambreeze
 
Dinamika partikel Mata Kuliah Konsep Dasar IPA
Dinamika partikel Mata Kuliah Konsep Dasar IPADinamika partikel Mata Kuliah Konsep Dasar IPA
Dinamika partikel Mata Kuliah Konsep Dasar IPA
lailam02
 
1D graphs, kinematics, and calculus
1D graphs, kinematics, and calculus1D graphs, kinematics, and calculus
1D graphs, kinematics, and calculus
cpphysics
 
Geometric transformation cg
Geometric transformation cgGeometric transformation cg
Geometric transformation cg
harinipriya1994
 
10 linescan
10 linescan10 linescan
10 linescan
Praveen Kumar
 
Motion 2 d
Motion  2 dMotion  2 d
Motion 2 d
wpchem81
 
1 d chapter 2
1 d chapter 21 d chapter 2
1 d chapter 2
mantlfin
 
Projectile motion
Projectile motionProjectile motion
Projectile motion
MrsWilliamsScience
 
Unit-3 overview of transformations
Unit-3 overview of transformationsUnit-3 overview of transformations
Unit-3 overview of transformations
Amol Gaikwad
 
2d transformations
2d transformations2d transformations
2d transformations
rajeshranjithsingh
 
Lecture Ch 02
Lecture Ch 02Lecture Ch 02
Lecture Ch 02
rtrujill
 
Fisika Dasar y n t ke 1
Fisika Dasar y n t ke 1Fisika Dasar y n t ke 1
Fisika Dasar y n t ke 1
555
 

Similar to Animation programming (20)

Projectile motion ch 5 reg
Projectile motion ch 5 regProjectile motion ch 5 reg
Projectile motion ch 5 reg
 
Physics - Chapter 2 - One Dimensional Motion
Physics - Chapter 2 - One Dimensional MotionPhysics - Chapter 2 - One Dimensional Motion
Physics - Chapter 2 - One Dimensional Motion
 
Chapter2powerpoint 090816163937-phpapp02
Chapter2powerpoint 090816163937-phpapp02Chapter2powerpoint 090816163937-phpapp02
Chapter2powerpoint 090816163937-phpapp02
 
Free fall PHYSICS IGCSE FORM 3 MRSM
Free fall PHYSICS IGCSE  FORM 3 MRSMFree fall PHYSICS IGCSE  FORM 3 MRSM
Free fall PHYSICS IGCSE FORM 3 MRSM
 
Intro to Game Programming
Intro to Game ProgrammingIntro to Game Programming
Intro to Game Programming
 
Introduction to Canvas - Toronto HTML5 User Group
Introduction to Canvas - Toronto HTML5 User GroupIntroduction to Canvas - Toronto HTML5 User Group
Introduction to Canvas - Toronto HTML5 User Group
 
Introduction to Canvas - Toronto HTML5 User Group
Introduction to Canvas - Toronto HTML5 User GroupIntroduction to Canvas - Toronto HTML5 User Group
Introduction to Canvas - Toronto HTML5 User Group
 
3 d transformation
3 d transformation3 d transformation
3 d transformation
 
Intro to Canva
Intro to CanvaIntro to Canva
Intro to Canva
 
Dinamika partikel Mata Kuliah Konsep Dasar IPA
Dinamika partikel Mata Kuliah Konsep Dasar IPADinamika partikel Mata Kuliah Konsep Dasar IPA
Dinamika partikel Mata Kuliah Konsep Dasar IPA
 
1D graphs, kinematics, and calculus
1D graphs, kinematics, and calculus1D graphs, kinematics, and calculus
1D graphs, kinematics, and calculus
 
Geometric transformation cg
Geometric transformation cgGeometric transformation cg
Geometric transformation cg
 
10 linescan
10 linescan10 linescan
10 linescan
 
Motion 2 d
Motion  2 dMotion  2 d
Motion 2 d
 
1 d chapter 2
1 d chapter 21 d chapter 2
1 d chapter 2
 
Projectile motion
Projectile motionProjectile motion
Projectile motion
 
Unit-3 overview of transformations
Unit-3 overview of transformationsUnit-3 overview of transformations
Unit-3 overview of transformations
 
2d transformations
2d transformations2d transformations
2d transformations
 
Lecture Ch 02
Lecture Ch 02Lecture Ch 02
Lecture Ch 02
 
Fisika Dasar y n t ke 1
Fisika Dasar y n t ke 1Fisika Dasar y n t ke 1
Fisika Dasar y n t ke 1
 

Recently uploaded

Ocean lotus Threat actors project by John Sitima 2024 (1).pptx
Ocean lotus Threat actors project by John Sitima 2024 (1).pptxOcean lotus Threat actors project by John Sitima 2024 (1).pptx
Ocean lotus Threat actors project by John Sitima 2024 (1).pptx
SitimaJohn
 
CAKE: Sharing Slices of Confidential Data on Blockchain
CAKE: Sharing Slices of Confidential Data on BlockchainCAKE: Sharing Slices of Confidential Data on Blockchain
CAKE: Sharing Slices of Confidential Data on Blockchain
Claudio Di Ciccio
 
How to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For FlutterHow to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For Flutter
Daiki Mogmet Ito
 
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
Edge AI and Vision Alliance
 
How to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptxHow to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptx
danishmna97
 
20240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 202420240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 2024
Matthew Sinclair
 
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with SlackLet's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
shyamraj55
 
UI5 Controls simplified - UI5con2024 presentation
UI5 Controls simplified - UI5con2024 presentationUI5 Controls simplified - UI5con2024 presentation
UI5 Controls simplified - UI5con2024 presentation
Wouter Lemaire
 
Mind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AIMind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AI
Kumud Singh
 
Taking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdfTaking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdf
ssuserfac0301
 
Best 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERPBest 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERP
Pixlogix Infotech
 
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdfUnlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Malak Abu Hammad
 
OpenID AuthZEN Interop Read Out - Authorization
OpenID AuthZEN Interop Read Out - AuthorizationOpenID AuthZEN Interop Read Out - Authorization
OpenID AuthZEN Interop Read Out - Authorization
David Brossard
 
Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
Alpen-Adria-Universität
 
Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024
Jason Packer
 
Full-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalizationFull-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalization
Zilliz
 
National Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practicesNational Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practices
Quotidiano Piemontese
 
Fueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte WebinarFueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte Webinar
Zilliz
 
AI-Powered Food Delivery Transforming App Development in Saudi Arabia.pdf
AI-Powered Food Delivery Transforming App Development in Saudi Arabia.pdfAI-Powered Food Delivery Transforming App Development in Saudi Arabia.pdf
AI-Powered Food Delivery Transforming App Development in Saudi Arabia.pdf
Techgropse Pvt.Ltd.
 
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success StoryDriving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Safe Software
 

Recently uploaded (20)

Ocean lotus Threat actors project by John Sitima 2024 (1).pptx
Ocean lotus Threat actors project by John Sitima 2024 (1).pptxOcean lotus Threat actors project by John Sitima 2024 (1).pptx
Ocean lotus Threat actors project by John Sitima 2024 (1).pptx
 
CAKE: Sharing Slices of Confidential Data on Blockchain
CAKE: Sharing Slices of Confidential Data on BlockchainCAKE: Sharing Slices of Confidential Data on Blockchain
CAKE: Sharing Slices of Confidential Data on Blockchain
 
How to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For FlutterHow to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For Flutter
 
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
 
How to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptxHow to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptx
 
20240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 202420240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 2024
 
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with SlackLet's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
 
UI5 Controls simplified - UI5con2024 presentation
UI5 Controls simplified - UI5con2024 presentationUI5 Controls simplified - UI5con2024 presentation
UI5 Controls simplified - UI5con2024 presentation
 
Mind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AIMind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AI
 
Taking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdfTaking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdf
 
Best 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERPBest 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERP
 
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdfUnlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
 
OpenID AuthZEN Interop Read Out - Authorization
OpenID AuthZEN Interop Read Out - AuthorizationOpenID AuthZEN Interop Read Out - Authorization
OpenID AuthZEN Interop Read Out - Authorization
 
Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
 
Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024
 
Full-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalizationFull-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalization
 
National Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practicesNational Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practices
 
Fueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte WebinarFueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte Webinar
 
AI-Powered Food Delivery Transforming App Development in Saudi Arabia.pdf
AI-Powered Food Delivery Transforming App Development in Saudi Arabia.pdfAI-Powered Food Delivery Transforming App Development in Saudi Arabia.pdf
AI-Powered Food Delivery Transforming App Development in Saudi Arabia.pdf
 
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success StoryDriving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success Story
 

Animation programming

  • 1.
  • 2. What is animation  Attributes can be varied › Position › Velocity › Accelration › Width, height › Rotation › Alpha › Time interval › Color  Easing  Bounce  Spring  Tweener › Performance issue  Creating Curve / Shapes / Volume › Application of curve  Using Vector › Optimizing ball collision demo
  • 3.
  • 4. What is animation? › Particle System Demo
  • 5. Change of Object’s Properties over time › What properties to change? › What objects to apply? › How to trigger the animation?
  • 6. Visible properties Invisible properties Position Velocity Scale Angular Velocity (width and height) Rotation Acceleration Alpha Angular Acceleration Color Loop interval (brightness, saturation, tone…) Depth Sound Volume Appearance (e.g. blur filter, shape)
  • 7.  Movieclips  Text Box  Sound Object  Camera (in 3D application)
  • 8. Static animation › Timeline › Pre-programmed animation  Dynamic animation › Mouse actions › Keyboard actions › Web Cam (Augmented Reality) › Microphone
  • 9. Initialization Animation Loop Update properties No Animation Ended? Yes Animation Ended
  • 10.
  • 11. We will go through… › Velocity › Acceleration › Friction › Boundaries › Easing and Springing › Angular Motion › Collision Detection › Frame-based VS Time-based
  • 12. Velocity › Rate of change of position over time  Acceleration › Rate of change of velocity over time  Useful formulae vx = vx + ax, vy = vy + ay x = x + vx, y = y + vy
  • 13. There can be energy loss when an object moves › Causing the object to slow down  An easy way to implement friction: vx *= friction factor vy *= friction factor where friction factor is from 0 to 1
  • 14. The previous method is only an approximation because: › In real physics, friction of a moving object has no relationship on velocity  Real Physics (acceleration = -0.2) t 0 1 2 3 4 5 v 10 8 6 4 2 0  Approximation (friction factor = 0.3): t 0 1 2 3 4 5 v 10 4 1.6 0.64 0.256 0.1024
  • 15. However, with the previous method: › Normal user should not be able to discover › No change of the sign of velocity  Write less “if then else” statements in code  The correct method: var speed:Number = Math.sqrt(vx * vx + vy * vy); var angle:Number = Math.atan2(vy, vx); if (speed > friction) { speed -= friction; } else { speed = 0; } vx = Math.cos(angle) * speed; vy = Math.sin(angle) * speed;
  • 16. Bouncing If (ball.x + ball.width / 2 > right || ball.x – ball.width / 2 < left) { ball.vx = -ball.vx; } If (ball.y + ball.height / 2 > bottom || ball.y – ball.height / 2 < top) { ball.vy = -ball.vy; }
  • 17. Bouncing with energy loss Without Energy loss With Energy loss If (ball.x + ball.width / 2 > right || ball.x – ball.width / 2 < left) { ball.vx = -ball.vx * friction; } If (ball.y + ball.height / 2 > bottom || ball.y – ball.height / 2 < top) { ball.vy = -ball.vy * friction; }
  • 18. Screen wrapping Re-appear in the other side!
  • 19. If (ball.x - ball.width / 2 > right ) { ball.x = left – ball.width / 2; } else if (ball.x _+ ball.width / 2 < left) { ball.x = right + ball.width / 2; } If (ball.y - ball.height / 2 > bottom) { ball.y = top – ball.height / 2; } else if (ball.y _+ ball.height / 2 < top) { ball.y = bottom + ball.height / 2; }
  • 20. Demo showing › Friction › Boundary › Energy loss hitting wall › throwing
  • 21.  Velocity is proportional to target distance  Object moves smoothly and decelerate to the target position displacement Target pos time
  • 22. Formula for easing x += (targetX – x) * easingFactor;; y += (targetY – y) * easingFactor;;
  • 23.  Acceleration is proportional to target distance  Objects move smoothly, vibrate and then slow down through the target position displacement Target pos time
  • 24. Formula for springing vx += (targetX – x) * springFactor; vy += (targetY – y) * springFactor; //add friction, otherwise the object will never stop vx *= frictionFactor; vy *= frictionFactor; x += vx; y += vy;
  • 25. In real world, › Objects usually move along an arced trajectory › Objects usually accelerates when start and decelerate when stop › This kind of motion create “natural” feeling to us › Easing is used entired in Mac OS / iPhone!
  • 26. Tweener is a well-known Flash tweening library http://code.google.com/p/tweener/  Easing can be done in just 1 statement › Can you read the meaning below? Tweener.addTween(this.ball, { x: 100, alpha: 0, time: 2, delay: 1, transition: easeOutExpo });
  • 27.
  • 28. Some famous tweening libraries › Tweener › TweenLite › Boostworthy Animation System › FuseKit › Go › KitchenSync  A comparison of these tweening libraries can be found at: http://dispatchevent.org/wp- content/uploads/2008/04/Tween-Engine- Comparisons.pdf
  • 29. Think in polar co-ordinate and then transform into the Cartesian Plane (x,y) x = r * Math.cos(θ); r y = r * Math.sin(θ); θ
  • 30. Angular Velocity › Rate of change of θ over time  Angular Acceleration › Rate of change of angular velocity over time  Angular Friction  Angular easing  Angular Springing
  • 31.
  • 32. Sine curve  Circle
  • 33. First person shooter game › Move up and down when walk  Biased Value Mapping › Random number biasing › My Website’s wallpaper rotator
  • 34. Rectangular Plane  Circular Plane  Cylinder  Cone  Helix  Sphere
  • 35.  Make code simpler  Same thinking in 2D and 3D space
  • 36.  Add  Subtraction  Scale  Dot production  Normalize  Get Length
  • 37. Collision Detection of a group of sphere  Explosion Effect in 3D space