Lecture22 Java3D - Interaction - This lecture will not be assessed.

Slides:



Advertisements
Similar presentations
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.
Advertisements

Module 8 “Polymorphism and Inheritance”. Outline Understanding Inheritance Inheritance Diagrams Constructors in Derived Classes Type Compatibility Polymorphism.
Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved. 1 Chapter 10 Behavior and Interaction.
1 Chapter 6: Extending classes and Inheritance. 2 Basics of Inheritance One of the basic objectives of Inheritance is code reuse If you want to extend.
Database Processing: Fundamentals, Design, and Implementation, 9/e by David M. KroenkeChapter 5/1 Copyright © 2004 Please……. No Food Or Drink in the class.
Inheritance Java permits you to use your user defined classes to create programs using inheritance.
1 of 25 Assignment Orthographic Wireframe Elevation Orthographic Wireframe Plan Orthographic Wireframe End-Elevation Perspective View.
Classes and Objects: Recap A typical Java program creates many objects which interact with one another by sending messages. Through the objects interactions,
Inheritance and Class Hierarchies Chapter 3. Chapter 3: Inheritance and Class Hierarchies2 Chapter Objectives To understand inheritance and how it facilitates.
Lecture21 Other Java Gamming technologies – Java3D (This lecture will not be assessed)
1 Software Testing and Quality Assurance Lecture 28 – Testing Class Hierarchies.
© 2006 Pearson Addison-Wesley. All rights reserved4-1 Chapter 4 Data Abstraction: The Walls.
1 Chapter 10 Behavior and Interaction  To understand dynamic behaviors in graphics  To understand Java 3D Behavior and WakeupCondition classes  To apply.
Java 3D Pablo Figueroa University of Alberta April 2000.
Classes and Objects  A typical Java program creates many objects which interact with one another by sending messages. Through the objects interactions,
Introduction to Java3D 1 3D-Pool Game Simulator CS491B Aslan Neishaboori.
Basic 3D Graphics Chapter 5. Bird’s Eye View  Basic 3D Graphics –Basic concepts of 3D graphics, rendering pipeline, Java 3D programming, scene graph,
1 Introduction to Java 3D Java 3D Overview v API for 3D applications v Portable.
Java ME & Blackberry APIs for Game Dev Week III. Overview Java 2D API Java 3D API SVG Blackberry APIs
Overview of Previous Lesson(s) Over View  OOP  A class is a data type that you define to suit customized application requirements.  A class can be.
CS324e - Elements of Graphics and Visualization Checkerboard World.
Java3D Overview Scene graph Java 3D classes Describing objects Groups, transforms Behaviors, interpolators Lighting.
1 Animation & Java3D ©Anthony Steed Overview n Introduction to Animation Kinematics Dynamics Boids n Java3D Scene graph Animation Vehicles.
Graphical Objects and Scene Graphs 1 Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009.
EEC-693/793 Applied Computer Vision with Depth Cameras Lecture 13 Wenbing Zhao
1 Abstraction  Identify important aspects and ignore the details  Permeates software development programming languages are abstractions built on hardware.
A Simple Talk on Java 3D Presented by C.H. Chen on Jul. 6, 2004.
INTRODUCTION TO JAVASCRIPT AND DOM Internet Engineering Spring 2012.
Lecture 3 Process Concepts. What is a Process? A process is the dynamic execution context of an executing program. Several processes may run concurrently,
(c) University of Washington07b-1 CSC 143 Java Events, Event Handlers, and Threads Reading: Ch. 17.
1 Compiler Construction (CS-636) Muhammad Bilal Bashir UIIT, Rawalpindi.
Chapter 9: Visual Programming Basics Object-Oriented Program Development Using Java: A Class-Centered Approach.
Chapter 4 Grouping Objects. Flexible Sized Collections  When writing a program, we often need to be able to group objects into collections  It is typical.
Object-Oriented Program Development Using Java: A Class-Centered Approach, Enhanced Edition.
Chapter 10 Defining Classes. The Internal Structure of Classes and Objects Object – collection of data and operations, in which the data can be accessed.
Events (Alice In Action, Ch 6) Slides Credit: Joel Adams, Alice in Action CS 120 Lecture September 2012.
Session 18 Chapter 8: Understanding Inheritance. Recall Exercise 2 From Tuesday It’s very annoying to move a target from the pallet and drop it in the.
Chapter 14 Applets and Advanced GUI  The Applet Class  The HTML Tag F Passing Parameters to Applets F Conversions Between Applications and Applets F.
Object Oriented Programming.  Interface  Event Handling.
Interface Opportunities for 3D Data and Media User Interface Software TechNote Panel Virginia Tech CS Fall 2002 Nicholas F. Polys Umur Yilmaz Will Lee.
Chapter 13 ATM Case Study Part 2: Implementing an Object-Oriented Design Java How to Program, 8/e (C) 2010 Pearson Education, Inc. All rights reserved.
Introduction to visual programming C#. Learning Outcomes In this chapter, you will learn about :  Event-Based Programming  The Event Based Model  Application.
Chapter 4 Grouping Objects. Flexible Sized Collections  When writing a program, we often need to be able to group objects into collections  It is typical.
1 5. Behavior Objects  Both interaction and animation are specified with objects  Both interaction and animation are specified with Behavior objects.
SCRIPT PROGRAMMING WITH FLASH Introductory Level 1.
Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved. 1 Chapter 5 Basic 3D Graphics.
Inheritance and Class Hierarchies Chapter 3. Chapter 3: Inheritance and Class Hierarchies2 Chapter Objectives To understand inheritance and how it facilitates.
Inheritance and Polymorphism. Superclass and Subclass Inheritance defines a relationship between objects that share characteristics. It is a mechanism.
Chapter 7 Classes and Methods III: Static Methods and Variables Lecture Slides to Accompany An Introduction to Computer Science Using Java (2nd Edition)
Kyung Hee University Class Diagramming Notation OOSD 담당조교 석사과정 이정환.
Object-Oriented Paradigm (OOP) Course Code: SE 101 Lecture No. 1.
Fundamentals of MyBATIS Improving performance with caching.
Modern Programming Tools And Techniques-I
Data Abstraction: The Walls
EEC-693/793 Applied Computer Vision with Depth Cameras
Chapter 3: Using Methods, Classes, and Objects
Important terms Black-box testing White-box testing Regression testing
Object-Oriented Programming
Important terms Black-box testing White-box testing Regression testing
3D-Online Product Configuration by Java3D
Lecture 22 Inheritance Richard Gesick.
Chapter 12 Exception Handling and Text IO
Implementing Classes Chapter 3.
1/10/2019 JavaFX Events COSC 330.
Event Driven Systems and Modeling
Events, Event Handlers, and Threads
Advanced ProgramMING Practices
Programming with inheritance Based on slides by Alyssa Harding
Advanced ProgramMING Practices
Simple Sequencing Part 2
Presentation transcript:

Lecture22 Java3D - Interaction - This lecture will not be assessed

The Behavior class Both interaction and animation are specified in terms of Behavior objects. Both interaction and animation are specified in terms of Behavior objects. The Behavior class is an abstract class that provides the mechanism to include code to change the scene graph. The Behavior class is an abstract class that provides the mechanism to include code to change the scene graph. The purpose of a scene graph is to change the scene graph, or objects on the scene graph, in response to some stimulus. The purpose of a scene graph is to change the scene graph, or objects on the scene graph, in response to some stimulus.

Stimulus and Changes A stimulus can be the press of a key, a mouse event, the collision of objects, the passage of time, some other event, or a combination of these. A stimulus can be the press of a key, a mouse event, the collision of objects, the passage of time, some other event, or a combination of these. Changes produced include Changes produced include adding objects to the scene graphadding objects to the scene graph Removing objects from the scene graphRemoving objects from the scene graph Changing the attributes of objects in the scene graph.Changing the attributes of objects in the scene graph. Rearranging objects in the scene graphRearranging objects in the scene graph Combination of theseCombination of these

The Behavior class hierarchy

Behavior method summary View getView() - Returns the primary view associated with this behavior. void initialize() - Initialize this behavior. void postId(int postId) - Post the specified Id. void processStimulus(java.util.Enumeration criteria) - Process a stimulus meant for this behavior. void setEnable(boolean state) - Enables or disables this Behavior. void setSchedulingBoundingLeaf(BoundingLeaf region) - Set the Behavior's scheduling region to the specified bounding leaf. void setSchedulingBounds(Bounds region) - Set the Behavior's scheduling region to the specified bounds. void wakeupOn(WakeupCondition criteria) - Defines this behavior's wakeup criteria.

WakeupCondition class hierarchy

Mechanics of Behaviors A custom behavior class A custom behavior class implements the initialization and processStimulas methods from the abstract Behavior class.implements the initialization and processStimulas methods from the abstract Behavior class. Has at least one constructor and may have other methods.Has at least one constructor and may have other methods. The object a behavior acts upon is referred to as the object of change. The object a behavior acts upon is referred to as the object of change. The behavior needs a reference to its objects of change to be able to make the behavioral changes. If it does not, another method in the custom behavior class must store this information.The behavior needs a reference to its objects of change to be able to make the behavioral changes. If it does not, another method in the custom behavior class must store this information. The reference is made at the time the scene graph is being constructed, which is the first computation of the behaviour.The reference is made at the time the scene graph is being constructed, which is the first computation of the behaviour.

Behavior – initialization and processStimulus The initialization method is invoked when the scene graph containing the behavior class becomes live. The initialization method is invoked when the scene graph containing the behavior class becomes live. The initialization method is responsible for setting the initial trigger event for the behavior and setting the initial conditions of the state variables for the behavior.The initialization method is responsible for setting the initial trigger event for the behavior and setting the initial conditions of the state variables for the behavior. The trigger is specified as a WakeupCondition object, or a combination of WakeupCondition objects. The trigger is specified as a WakeupCondition object, or a combination of WakeupCondition objects. The processStimulus method is invoked when the trigger event specified for the behavior occurs. The processStimulus method is invoked when the trigger event specified for the behavior occurs.

Mechanics of Behavior – basic recipe 1. write (at least one) constructor store a reference to the object of change 2. override public void initialization() specify initial wakeup criteria (trigger) 3. override public void processStimulus() decode the trigger condition act according to the trigger condition reset trigger as appropriate

Example Making something rotate a fixed angle in response to a keyboard key press: Making something rotate a fixed angle in response to a keyboard key press: The constructor will store a reference to the TransformGroup object of change.The constructor will store a reference to the TransformGroup object of change. The initialization method sets the initial trigger to WakeOnAWTEvent, and sets the rotation angle to zero.The initialization method sets the initial trigger to WakeOnAWTEvent, and sets the rotation angle to zero. The stimulus to a behavior is specified as a WakeupCondition object.The stimulus to a behavior is specified as a WakeupCondition object.

Example import java.awt.event.*; import java.util.Enumeration; public class SimpleBehavior extends Behavior{ // private variables private TransformGroup targetTG; private Transform3D rotation = new Transform3D(); private double angle = 0.0; // create SimpleBehavior - set TG object of change SimpleBehavior(TransformGroup targetTG){ this.targetTG = targetTG; } … }

Example import java.awt.event.*; import java.util.Enumeration; public class SimpleBehavior extends Behavior{ private TransformGroup targetTG; private Transform3D rotation = new Transform3D(); private double angle = 0.0; … // initialize the Behavior // set initial wakeup condition // called when behavior becomes live public void initialize(){ // set initial wakeup condition this.wakeupOn(new WakeupOnAWTEvent(KeyEvent.KEY_PRESSED)); } … }

Example import java.awt.event.*; import java.util.Enumeration; public class SimpleBehavior extends Behavior{ private TransformGroup targetTG; private Transform3D rotation = new Transform3D(); private double angle = 0.0; … // called by Java 3D when appropriate stimulus occurs public void processStimulus(Enumeration criteria){ // do what is necessary in response to stimulus angle += 0.1; rotation.rotY(angle); targetTG.setTransform(rotation); this.wakeupOn(new WakeupOnAWTEvent(KeyEvent.KEY_PRESSED)); }

Bounds of the Behavior Java3D uses scheduling bounds to perform execution culling. Java3D uses scheduling bounds to perform execution culling. Behavior is only active when its scheduling bounds intersects a ViewPlatform’s activation volume.Behavior is only active when its scheduling bounds intersects a ViewPlatform’s activation volume. Only active behaviors are eligible to receive stimuli.Only active behaviors are eligible to receive stimuli.

Recipe for using a Behavior class 1.Prepare the scene graph (by adding a transformation group or other objects). 2.Insert behavior objects in the scene graph, referencing the object of change. 3.Specify a scheduling bounds (or SchedulingBoundingLeaf) 4.Set write (and read) capabilities for the target object

Example – using a behavior class public BranchGroup createSceneGraph() { // Create the root of the branch graph BranchGroup objRoot = new BranchGroup(); TransformGroup objRotate = new TransformGroup(); objRotate.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); objRoot.addChild(objRotate); objRotate.addChild(new ColorCube(0.4)); SimpleBehavior myRotationBehavior = new SimpleBehavior(objRotate); myRotationBehavior.setSchedulingBounds(new BoundingSphere()); objRoot.addChild(myRotationBehavior); // Let Java 3D perform optimizations on this scene graph. objRoot.compile(); return objRoot; }

Example – using a behavior class – the scene graph

Behavior class – Programming pitfalls In the recipe of custom behavior class recipe two most likely programming mistakes are In the recipe of custom behavior class recipe two most likely programming mistakes are Forgetting to set and reset the behavior triggerForgetting to set and reset the behavior trigger If the initial trigger is not set in the initialization method, the behavior will never be invoked. If the initial trigger is not set in the initialization method, the behavior will never be invoked. The trigger must be set again in the processStimulus method if a repeat behavior is desired. The trigger must be set again in the processStimulus method if a repeat behavior is desired. Not returning from the behavior class methodsNot returning from the behavior class methods Both initialization and processStimulus methods must return to allow the rendering to continue. Both initialization and processStimulus methods must return to allow the rendering to continue. Example: if a spinning behavior is desired, the angle and the TransformGroup would need to be updated periodically. If your behavior implemented this behavior without spawning a thread, nothing further would be rendered. Example: if a spinning behavior is desired, the angle and the TransformGroup would need to be updated periodically. If your behavior implemented this behavior without spawning a thread, nothing further would be rendered.

Keyboard Navigation

If the view platform transform is changed, the effect is to move, or re- orient, or both, the viewer. If the view platform transform is changed, the effect is to move, or re- orient, or both, the viewer. The basic design of keyboard navigation is simple: have the behavior object change the view platform transform in response to key strokes. The basic design of keyboard navigation is simple: have the behavior object change the view platform transform in response to key strokes.

Keyboard Navigation - Recipe 1. create a KeyNavigatorBehavior object, setting the transform group 2. add the KeyNavigatorBehavior object to the scene graph 3. provide a bounds (or BoundingLeaf) for the KeyNavigatorBehavior object

Keyboard Navigation - Example public BranchGroup createSceneGraph(SimpleUniverse su) { TransformGroup vpTrans = null; // Create the root of the branch graph BranchGroup objRoot = new BranchGroup(); objRoot.addChild(createLand()); … // create other scene graph content vpTrans = su.getViewingPlatform().getViewPlatformTransform(); translate.set( 0.0f, 0.3f, 0.0f); // 3 meter elevation Transform3D.setTranslation(translate); // set as translation vpTrans.setTransform(T3D); // used for initial position KeyNavigatorBehavior keyNavBeh = new KeyNavigatorBehavior(vpTrans); keyNavBeh.setSchedulingBounds(new BoundingSphere(new Point3d(),1000.0)); objRoot.addChild(keyNavBeh); objRoot.compile(); return objRoot; }