240-571 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,

Slides:



Advertisements
Similar presentations
MIDP Mobile Information Device Profile Johnny Yau CIS 642 Prof. Insup Lee.
Advertisements

2D Graphics Drawing Things. Graphics In your GUI, you might want to draw graphics E.g. draw lines, circles, shapes, draw strings etc The Graphics class.
Made with love, by Zachary Langley Applets The Graphics Presentation.
Java 2D Training. Basic Tools Java SDK 1.4x Wireless Toolkit 2.x NetBeans IDE + mobility pack Global Code editor Text Comparer Tools Graphics Editor Sprite.
Graphics You draw on a Graphics object The Graphics object cannot directly be created by your code, instead one is generated when the method paintComponent.
Multithreading : animation. slide 5.2 Animation Animation shows different objects moving or changing as time progresses. Thread programming is useful.
More Java Drawing in 2D Animations with Timer. Drawing Review A simple two-dimensional coordinate system exists for each graphics context or drawing surface.
Java.sun.com/javaone/sf | 2004 JavaOne SM Conference | Session TS Advanced Game Development with the Mobile 3D Graphics API Tomi Aarnio, Kari Pulli.
COSC 4126 images - D Goforth Images, Buffering and Animation controlling full screen graphics.
J2ME 25 July Overview  What is J2ME?  The CLDC and CDC configurations  MIDP and MIDlets  Development Tools  Demonstrations.
Graphics Programming UQC117S2 Semester /4. Session 3 1 Drawing in Java 2D Graphics API.
Lecture21 Other Java Gamming technologies – Java3D (This lecture will not be assessed)
Making Cell Phone Games An Overview Ray Ratelis Guild Software, Inc.
Developing J2ME Applications Mobile and Wireless Networks.
Cosc 4730 Phone Programming in Java An Introduction.
Java 2 Platform, Micro Edition (J2ME) By Xiaorong Wang.
Week 1 - Friday.  What did we talk about last time?  C#  SharpDX.
Basic 3D Graphics Chapter 5. Bird’s Eye View  Basic 3D Graphics –Basic concepts of 3D graphics, rendering pipeline, Java 3D programming, scene graph,
Applets  The Applet Class  The HTML Tag F Passing Parameters to Applets.
CS324e - Elements of Graphics and Visualization Checkerboard World.
3D Objects Subject:T0934 / Multimedia Programming Foundation Session:12 Tahun:2009 Versi:1/0.
EEC-693/793 Applied Computer Vision with Depth Cameras Lecture 13 Wenbing Zhao
Internet Software Development Applets Paul J Krause.
Week 2 - Wednesday CS361.
A Simple Talk on Java 3D Presented by C.H. Chen on Jul. 6, 2004.
CSE 219 Computer Science III Images. HW1 Has been posted on Blackboard Making a Game of Life with limited options.
Programming Handheld and Mobile devices 1 Programming of Handheld and Mobile Devices Lecture 12 lcdui Rob Pooley
Programming Handheld and Mobile devices 1 Programming of Handheld and Mobile Devices Lecture 13 lcdui and OXO Rob Pooley
Addison Wesley is an imprint of © 2010 Pearson Addison-Wesley. All rights reserved. Chapter 7 The Game Loop and Animation Starting Out with Games & Graphics.
Seminar 1 Scene graph & Hierarchical animation EDA221 Introduction to Computer Graphics Carl Johan Gribel, PhD student
Canvas and Graphics CS 21a. 9/26/2005 Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved L17: Canvas.
Java Applets 1. What is an applet? An applet is a small Java program that is typically embedded in a Web page and can be run using the applet viewer or.
Other Popular Java Technologies Internationalization in Java Graphics Programming in Java Security Programming in Java Collections and Data Structures.
PHY281 Scientific Java Programming LoopsSlide 1 Loops In this section we will learn how to repeat a series of instructions using loops and to use this.
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.
Modeling with OpenGL Practice with OpenGL transformations.
Creating Your Own Widgets CompSci 230 S Software Construction.
Review Inheritance Overloading and overriding. example1.pde.
BallWorld.java A structured walkthrough. Key Features: 2 classes are created Execution is done through the procedure called “main” which are decleared.
Objects and Classes Chapter Nine. Definition “an object is a combination of some data (variables) and some actions (methods)”. Hopefully the data and.
Lesson 3: Arrays and Loops. Arrays Arrays are like collections of variables Picture mailboxes all lined up in a row, or storage holes in a shelf – You.
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.
Simple Scene Management a layer has the size of the device screen it defines appearance and behavior a scene is composed of one or more layers app transitions.
Object-Oriented Software Engineering Using Threads and simple Animation.
 Learn some important functions and process in OpenGL ES  Draw some triangles on the screen  Do some transformation on each triangle in each frame.
11 Writing Text Session 5.1. Session Overview  Show how fonts are managed in computers  Discover the difference between bitmap fonts and vector fonts.
Overview  Basic requirements of implementation  Image resource  Texture mapping  Advanced requirements of implementation  KGL sprite class.
1 Drawing C Sc 335 Object-Oriented Programming and Design Rick Mercer.
1 Introduction to J2ME Outline MIDP Building J2ME Apps- Tool J2ME Wireless Toolkit Demo MIDlet Programming -- MIDlet Transition States -- Midlet Skeleton.
XNA Tutorial 1 For CS134 Lecture. Overview Some of the hard work has already been done for you. If you build and run your game now, the GraphicsDeviceManager.
Java Applets Adding Animation. Import Files You still need to include the same files: –import java.applet.*; –import java.awt.*;
Programming and Problem Solving With Java Copyright 1999, James M. Slack Threads and Animation Threads Animation.
Mobile & Casual Gaming OpenGL ES Intro. /red/chapter03.html.
By: Eliav Menachi.  Android custom 2D graphics library  OpenGL ES 1.0 for high performance 3D graphics.
 It is a pure oops language and a high level language.  It was developed at sun microsystems by James Gosling.
EEC-693/793 Applied Computer Vision with Depth Cameras
Quick Intro to Unity Lecture 2.
Creating Your Own Widgets
Graphical Output Basic Images.
Layers in Adobe After Effect
Week 2 - Monday CS361.
IAT 355 Scene Graphs Feb 23, 2017 IAT 355.
EEC-693/793 Applied Computer Vision with Depth Cameras
Lecture 8: Graphics By: Eliav Menachi.
GIF's by POV-Ray and GIAM a tiny crash course
EEC-693/793 Applied Computer Vision with Depth Cameras
Basic Graphics Drawing Shapes 1.
Computer Graphics 4Practical Lesson
EEC-693/793 Applied Computer Vision with Depth Cameras
Mobile Computing With Android ACST 4550 Android Animation
Presentation transcript:

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, penguin, and animation details until next time , Semester 2, M3G. Part 1

J2ME: M3G/12 1. Features v M3G: the Mobile 3D Graphics API –developed as JSR-184 –present in WTK 2.2 and later –a combination of high-level and low-level features u retained and immediate modes –combined with J2ME via the Canvas or GameCanvas classes

J2ME: M3G/13 v No callbacks v No separate rendering thread –so you must code your own animation loop using a timer or a thread v Requires CLDC 1.1. for floats –make sure to select it in the WTK

J2ME: M3G/14 Two Modes v Retained Mode (high-level API) –build a 3D scene by building a scene graph –the scene graph is rendered automatically –similar to Java 3D, but a much smaller API u and a few extras v Immediate Mode (low-level API) –based on OpenGL ES –no scene graph data structure

J2ME: M3G/15 Scene Graph Example World Group Mesh Sprite Group CameraLight a World object is the top node

J2ME: M3G/16 v Mesh: a 3D model –subclasses: morphing mesh, skinned mesh v Sprite: a 2D image v A Group is a useful way of grouping objects so they can be transformed with a single operation. v Typical transformations: –scaling, rotation, translation –animation based on key frames

J2ME: M3G/17 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/18 2. WTK 2.2 Examples v v Life3D – –the Game of Life in 3D v v PogoRoo – –a kangaroo bouncing on a pogo stick v v retainedmode – –animates a skateboarder model u a M3D file

J2ME: M3G/19 Hello World public class Test extends MIDlet { private MyCanvas c = new MyCanvas(); protected void startApp() { Display.getDisplay(this).setCurrent(c); } protected void pauseApp() {} protected void destroyApp() {} }

J2ME: M3G/110 public class MyCanvas extends Canvas { private Graphics3D iG3D; // for rendering private World scene; // for the scene graph public MyCanvas() { iG3D = Graphics3D.create(); scene = (World) Loader.load(”/w.m3d”)[0]; } protected void paint(Graphics g) { iG3D.bindTarget(g); iG3D.render( scene ); iG3D.releaseTarget(); // flush }

J2ME: M3G/111 Animated World public class Test extends MIDlet { MyCanvas c = new MyCanvas(); MyTimer updater = new MyTimer();... private class MyTimer extends TimerTask { public MyTimer() { new Timer().schedule(this,0,40); } // 40ms public void run() { c.repaint(); } }

J2ME: M3G/112 public class MyCanvas extends Canvas { int time = 0;... protected void paint(Graphics g) { iG3D.bindTarget(g); scene.animate(time += 40); // 25 fps iG3D.render( scene ); iG3D.releaseTarget(); }

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

J2ME: M3G/ 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/115 AnimM3G Class Diagrams MIDlet Canvas CommandListener TimerTask

J2ME: M3G/116 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/ AnimCanvas Constructor private World scene; // global variable public AnimCanvas(...) { //... other code scene = new World(); buildScene(); //... other code }

J2ME: M3G/118 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/ Adding the Camera private void addCamera() { Camera cam = new Camera(); float aspectRatio = ((float) getWidth()) / ((float) getHeight()); cam.setPerspective(70.0f, aspectRatio, 0.1f, 50.0f); cam.setTranslation(0.0f, 0.5f, 2.0f); // up and back // cam.setOrientation(-10.0f, 1.0f, 0, 0); // angle downwards slightly scene.addChild(cam); scene.setActiveCamera(cam); }

J2ME: M3G/120 AnimM3G Viewed from Above cam.setTranslation(0.0f, 5.0f, 0.0f); cam.setOrientation(-90.0f, 1.0f, 0, 0);

J2ME: M3G/ Adding a Light private void addLight() { Light light = new Light(); // default white, directional light light.setIntensity(1.25f); // make it a bit brighter light.setOrientation(-45.0f, 1.0f, 0, 0); // down and into scene scene.addChild(light); }

J2ME: M3G/ Adding a Background private void addBackground() { Background backGnd = new Background(); backGnd.setColor(0x00bffe); // a light blue background scene.setBackground(backGnd); }

J2ME: M3G/123 Clouds in the BackGround

J2ME: M3G/124 A Background Image private void addBackground() { Background backGnd = new Background(); Image2D backIm = loadImage("/clouds.gif"); // cloudy blue sky if (backIm != null) { backGnd.setImage(backIm); backGnd.setImageMode(Background.REPEAT, Background.REPEAT); } else backGnd.setColor(0x00bffe); // a light blue background scene.setBackground(backGnd); }

J2ME: M3G/125 private Image2D loadImage(String fn) { Image2D im = null; try { im = (Image2D) Loader.load(fn)[0]; } catch (Exception e) { System.out.println( "Cannot make image from " + fn); } return im; } // end of loadImage()

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/127 The Floor Grid Image

J2ME: M3G/ 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/129 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/131 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/132 Rendering the Scene private Graphics3D iG3D; // global public AnimCanvas(AnimM3G top) { // other code... iG3D = Graphics3D.getInstance(); } protected void paint(Graphics g) { iG3D.bindTarget(g); try { iG3D.render(scene); } catch(Exception e) { e.printStackTrace(); } finally { iG3D.releaseTarget(); } // show the model's coordinates in MIDP g.drawString( animModel.getPosition(), 5,5, Graphics.TOP|Graphics.LEFT); } safer coding style