240-571 J2ME: M3G/11 Intro to J2ME. Prog. v Objectives: –to continue talking about "M3G Chapter 2. An Animated Model" u explain animation and the floor.

Slides:



Advertisements
Similar presentations
Today Composing transformations 3D Transformations
Advertisements

Java.sun.com/javaone/sf | 2004 JavaOne SM Conference | Session TS Advanced Game Development with the Mobile 3D Graphics API Tomi Aarnio, Kari Pulli.
Informationsteknologi Wednesday, November 7, 2007Computer Graphics - Class 51 Today’s class Geometric objects and transformations.
1 Computer Graphics Week6 –Basic Transformations- Translation & Scaling.
FUNDAMENTALS OF PROGRAMMING SM1204 Semester A 2011.
2.1 si SI31 Advanced Computer Graphics AGR Lecture 2 Basic Modelling.
REFLECTIONS, ROTATIONS AND TRANSLATIONS. Reflections.
CHAPTER 7 Viewing and Transformations © 2008 Cengage Learning EMEA.
Hierarchical Transformations Hierarchical Models Scene Graphs
1 Texture Chapter 6. 2 What is Texture? Texture is a D3D interface that can map a partial of a picture to a 3D space by using Texture coordinates. The.
1 X file & Mesh Chapter 8. 2 What is X file? 1.X file is a file that is used to store D3D program's data. 2.Any X file has extension *.x. 3.X file could.
2.4: Rotations.
CSE 381 – Advanced Game Programming 3D Mathematics
Shapes Properties Binding Chung Ji Hye.
CS324e - Elements of Graphics and Visualization Checkerboard World.
J2ME: M3G/11 Intro to J2ME. Prog. v Objectives: –to introduce M3G; –to start talking about "M3G Chapter 2. An Animated Model" u leave the floor,
1 Ring, Circle, Cone Chapter 4. 2 Triangle rotating We have a triangle in the following position We want to rotate it around line y =  2. For this purpose,
Graphics Graphics Korea University kucg.korea.ac.kr Transformations 고려대학교 컴퓨터 그래픽스 연구실.
Buffers Textures and more Rendering Paul Taylor & Barry La Trobe University 2009.
Chapter 7 Transformations. Chapter Objectives Identify different types of transformations Define isometry Identify reflection and its characteristics.
Section 9-5 Hyperbolas. Objectives I can write equations for hyperbolas I can graph hyperbolas I can Complete the Square to obtain Standard Format of.
Section Recall Then you applied these to several oblique triangles and developed the law of sines and the law of cosines.
Introduction to XNA Graphics Programming Asst. Prof. Rujchai Ung-arunyawee COE, KKU.
Lesson 9-6 Vectors.
1 Viewing & Projective Window Chapter 3. 2 D3D virtual viewpoint Definition: virtual viewpoint is like a camera that was positioned in some where and.
Algebraic Representations of Transformations Day 2
Jinxiang Chai Composite Transformations and Forward Kinematics 0.
Chapter 7 Transformations. Examples of symmetry Lines of Symmetry.
1 Manage Mesh Data Chapter 8. 2 How to manage Mesh data The most important two objects of mesh are VertexBuffer and IndexBuffer, which can obtained by.
Modeling with OpenGL Practice with OpenGL transformations.
1 Perception and VR MONT 104S, Fall 2008 Lecture 21 More Graphics for VR.
Review Inheritance Overloading and overriding. example1.pde.
Transformations Objective: to develop an understanding of the four transformations. Starter – if 24 x 72 = 2016, find the value of: 1)2.8 x 72 = 2)2.8.
Angles and the Unit Circle. An angle is in standard position when: 1) The vertex is at the origin. 2) One leg is on the positive x – axis. (This is the.
Lesson 9-R Chapter 9 Review. Objectives Review chapter 9 material.
Transformations Translation Reflection Rotation Dilation.
1 9 Lighting a Scene v There are four types of lighting: –ambient light –directional light –point light –spotlight v Any number of these can be added to.
Geometric Objects and Transformations. Graphics Pipeline How can we render a triangle? High-level description: – Represent the 3D geometry – Transform.
Image-based Rendering Ref: RTRv2. 2 Introduction Sprite, billboard, overview.
Algebra 4-2 Transformations on the Coordinate Plane
FUNDAMENTALS OF PROGRAMMING SM1204 SEMESTER A 2012.
9-2 Reflections Objective: To find reflection images of figures.
 Advancing from moving premade primitives to making our own models  Two different approaches: ◦ Direct mesh editing: A more traditional approach commonly.
Transformations on the Coordinate Plane Transformations are movements of geometric figures. The preimage is the position of the figure before the transformation,
Day 4 Special right triangles, angles, and the unit circle.
Coordinates and Design. What You Will Learn: To use ordered pairs to plot points on a Cartesian plane To draw designs on a Cartesian plane To identify.
Design Visualization Software Introduction / Review.
Geometric Transformations Ceng 477 Introduction to Computer Graphics Computer Engineering METU.
13-2 ANGLES AND THE UNIT CIRCLE FIND ANGLES IN STANDARD POSITION BY USING COORDINATES OF POINTS ON THE UNIT CIRCLE.
3D Ojbects: Transformations and Modeling. Matrix Operations Matrices have dimensions: Vectors can be thought of as matrices: v=[2,3,4,1] is a 1x4 matrix.
Quick Intro to Unity Lecture 2.
2.2: Translations.
Warm Up A figure has vertices A, B, and C. After a transformation, the image of the figure has vertices A′, B′, and C′. Draw the pre-image and the image.
3B Reflections 9-2 in textbook
Translations 9.2 Content Standards
Translations.
Assignment 8 Chess Game.
A movement of a figure in a plane.
A movement of a figure in a plane.
Congruence and Transformations
9.1: Reflections.
Computer Graphics 4Practical Lesson
Game Programming Algorithms and Techniques
Transformations Translation Reflection The FRAME Routine
Objective Identify and draw rotations..
Objective Identify and draw dilations..
Practice Test for Chapter 7 - Transformations
Presentation transcript:

J2ME: M3G/11 Intro to J2ME. Prog. v Objectives: –to continue talking about "M3G Chapter 2. An Animated Model" u explain animation and the floor u leave the penguin until next time , Semester 2, M3G. Part 2

J2ME: M3G/12 1. M3G Chapter 2. An Animated Model v Make a penguin walk in circles

J2ME: M3G/13 Features v Uses retained mode. v The scene includes a single directional light, a textured floor, a light blue background –or an image background v Mixes M3G rendering and MIDP's drawString() v Penguin model is an animated Mesh –it translates and rotates

J2ME: M3G/14 AnimM3G Class Diagrams MIDlet Canvas CommandListener TimerTask

J2ME: M3G/15 Scene Graph World scene LightBackgroundCamera Mesh floorMesh Group built by the Floor class Mesh model transRotGroup animated built by the AnimModel class scene graph children

J2ME: M3G/16 AnimCanvas Constructor private World scene; // global variable public AnimCanvas(...) { //... other code scene = new World(); buildScene(); //... other code }

J2ME: M3G/17 private void buildScene() // add nodes to the scene graph { addCamera(); addLight(); addBackground(); animModel = new AnimModel(); scene.addChild( animModel.getModelGroup() ); // add the model addFloor(); } // end of buildScene()

J2ME: M3G/18 Adding the Penguin // global for translating and rotating the model private Group transRotGroup; public AnimModel() { // other code... Mesh model = makeModel(); // reposition the model's start position and size model.setTranslation(0.25f, 0.25f, 0.25f); // so at center model.scale(0.5f, 0.5f, 0.5f); // translation/rotation group for the model transRotGroup = new Group(); transRotGroup.addChild(model); // other code... }

J2ME: M3G/19 Changing the Penguin's Position Mesh model = makeModel(); // reposition the model's start position and size model.setTranslation(0.25f, 0.25f, 0.25f); // so at center model.scale(0.5f, 0.5f, 0.5f);

J2ME: M3G/ Updating the Application timer run() { animCanvas.update(); } AnimTimer (in AnimM3G) update() { // increment world time // call animate() on world // call repaint() } AnimCanvas paint() { // render the 3D scene // draw 2D info. string } AnimCanvas call run() every PERIOD ms update the canvas KVM repaint request

J2ME: M3G/111 AnimCanvas // global timing information private int appTime = 0; private int nextTimeToAnimate; public AnimCanvas(AnimM3G top) { // other code... // start the animation nextTimeToAnimate = scene.animate(appTime); } public void update() // called by TimerTask every PERIOD (50) ms { appTime++; if (appTime >= nextTimeToAnimate) { nextTimeToAnimate = scene.animate(appTime) + appTime; repaint(); } }

J2ME: M3G/ Animating the Penguin

J2ME: M3G/113 From time to Update AnimationTrack Animation Controller Keyframe Sequence twtw twtw tsts tsts update property frame t w = world time t s = sequence time t s = speed*(t w – tRef w ) + tRef s

J2ME: M3G/114 A Keyframe Sequence

J2ME: M3G/115 Initializing the Animation private void setUpAnimation() { // creation animation controller AnimationController animController = new AnimationController(); animController.setActiveInterval(0, 1500); // animController.setSpeed(2.0f, 0); // creation translation animation track KeyframeSequence transKS = translateFrames(); AnimationTrack transTrack = new AnimationTrack(transKS, AnimationTrack.TRANSLATION); transTrack.setController(animController); transRotGroup.addAnimationTrack(transTrack); :

J2ME: M3G/116 // creation rotation animation track KeyframeSequence rotKS = rotationFrames(); AnimationTrack rotTrack = new AnimationTrack(rotKS, AnimationTrack.ORIENTATION); rotTrack.setController(animController); transRotGroup.addAnimationTrack(rotTrack); } // end of setUpAnimation()

J2ME: M3G/117 Translation KeyFrames

J2ME: M3G/118 Translation Frame Sequence

J2ME: M3G/119 Code for Sequence private KeyframeSequence translateFrames() { KeyframeSequence ks = new KeyframeSequence(8, 3, KeyframeSequence.SPLINE); ks.setKeyframe(0,0, new float[] { -0.5f,0.0f, 0.0f }); ks.setKeyframe(1,10, new float[] { f,0.0f,0.3536f }); ks.setKeyframe(2,20, new float[] { 0.0f, 0.0f, 0.5f }); ks.setKeyframe(3,30, new float[] { f,0.0f, f }); ks.setKeyframe(4,40, new float[] { 0.5f, 0.0f, 0.0f }); ks.setKeyframe(5,50, new float[] { f,0.0f, f }); ks.setKeyframe(6,60, new float[] { 0.0f, 0.0f, -0.5f }); ks.setKeyframe(7,70, new float[] { f,0.0f, f }); :

J2ME: M3G/120 ks.setDuration(80); // one cycle takes 80 seq time units ks.setValidRange(0, 7); ks.setRepeatMode(KeyframeSequence.LOOP); return ks; } // end of translateFrames()

J2ME: M3G/121 Rotation Keyframes

J2ME: M3G/122 Rotation Frame Sequence

J2ME: M3G/123 Code for Sequence private KeyframeSequence rotationFrames() { KeyframeSequence ks = new KeyframeSequence(8,4,KeyframeSequence.SLERP); ks.setKeyframe(0, 0, rotYQuat(0)); ks.setKeyframe(1, 10, rotYQuat(45)); ks.setKeyframe(2, 20, rotYQuat(90)); ks.setKeyframe(3, 30, rotYQuat(135)); ks.setKeyframe(4, 40, rotYQuat(180)); ks.setKeyframe(5, 50, rotYQuat(225)); ks.setKeyframe(6, 60, rotYQuat(270)); ks.setKeyframe(7, 70, rotYQuat(315)); ks.setDuration(80); ks.setValidRange(0, 7); ks.setRepeatMode(KeyframeSequence.LOOP); return ks; } // end of rotationFrames()

J2ME: M3G/124 Axis-Angle Rotation v axis-angle = [Vx, Vy, Vz, angle] V angle

J2ME: M3G/125 To Quaternions v The axis angle [Vx,Vy,Vz, angle] becomes the quaternion: –[ sin(angle/2)*Vx, sin(angle/2)*Vy, sin(angle/2)*Vz, cos(angle/2) ] –called [i, j, k, scalar] u 4 values

J2ME: M3G/126 What is a Quaternion? v It defines a point on a 4D sphere! v Rotation between two quaternions is the same as a constant speed movement between the two points using the shortest distance.

J2ME: M3G/127 Rotation Around the Y-axis private float[] rotYQuat(double angle) /* Calculate the quaternion for a clockwise rotation of angle degress about the y-axis. */ { double radianAngle = Math.toRadians(angle)/2.0; float[] quat = new float[4]; quat[0] = 0.0f; // i coefficient quat[1] = (float) Math.sin(radianAngle); // j coef quat[2] = 0.0f; // k coef quat[3] = (float) Math.cos(radianAngle); // scalar component a return quat; } // end of rotYQuaternion()

J2ME: M3G/ Mesh Details VertexBuffer IndexBuffer Appearance composed of 1 or more VertexBuffer positions VertexArray normals VertexArray colours VertexArray composed of 0 or 1 tex. coords. VertexArray 0 or more Appearance Material PolygonMode CompositingMode composed of Fog Texture2D Image2D 1 or more Mesh

J2ME: M3G/129 Vertex Indicies v Vertex indicies {0, 1, 2, 3, 4, 5} are organised into a triangle strip: Triangles: (0,1,2) (1,2,3) (2,3,4) (3,4,5)

J2ME: M3G/ Adding the Floor private void addFloor() { Image2D floorIm = loadImage("/bigGrid.gif"); // large, so slow to load Floor f = new Floor( floorIm, 8); //8 by 8 sz // Image2D floorIm = loadImage("/grass.gif"); // or try "/floor.png" // Floor f = new Floor( floorIm, 6);// 6 by 6 scene.addChild( f.getFloorMesh() ); }

J2ME: M3G/131 The Floor Grid Image

J2ME: M3G/132 Making the Floor Triangles: (1,2,0) (2,0,3) Triangle strip: {1, 2, 0, 3}

J2ME: M3G/133 Texture Coordinates

J2ME: M3G/134 Code private Mesh floorMesh; public Floor(Image2D floorIm, int size) { VertexBuffer floorVertBuf = makeGeometry(size); int[] indicies = {1,2,0,3}; // one quad int[] stripLens = {4}; IndexBuffer floorIdxBuf = new TriangleStripArray(indicies, stripLens); Appearance floorApp = makeAppearance(floorIm); floorMesh = new Mesh(floorVertBuf, floorIdxBuf, floorApp); } // end of Floor()

J2ME: M3G/135 private VertexBuffer makeGeometry(int size) /* A square centered at the origin on the XZ plane with sides of length size. No normals. */ { // create vertices short pt = (short)(size/2); short npt = (short) (-size/2); // negative pt short[] verts = {npt,0,pt, pt,0,pt, pt,0,npt, npt,0,npt}; VertexArray va = new VertexArray(verts.length/3, 3, 2); va.set(0, verts.length/3, verts); :

J2ME: M3G/136 // create texture coordinates short[] tcs = {0,1, 1,1, 1,0, 0,0}; VertexArray texArray = new VertexArray(tcs.length/2, 2, 2); texArray.set(0, tcs.length/2, tcs); VertexBuffer vb = new VertexBuffer(); vb.setPositions(va, 1.0f, null); // no scale, bias vb.setTexCoords(0, texArray, 1.0f, null); return vb; } // end of makeGeometry()

J2ME: M3G/137 private Appearance makeAppearance(Image2D floorIm) // The appearance is only a single texture; no material. { Appearance app = new Appearance(); if (floorIm != null) { Texture2D tex = new Texture2D(floorIm); tex.setFiltering(Texture2D.FILTER_NEAREST, Texture2D.FILTER_NEAREST); tex.setWrapping(Texture2D.WRAP_CLAMP, Texture2D.WRAP_CLAMP); app.setTexture(0, tex); } :

J2ME: M3G/138 // add perspective correction, and switch off culling PolygonMode floorPolygonMode = new PolygonMode(); floorPolygonMode.setPerspectiveCorrectionEnable(true); floorPolygonMode.setCulling(PolygonMode.CULL_NONE); app.setPolygonMode(floorPolygonMode); return app; } // end of makeAppearance()