Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved. 1 Chapter 8 Views
Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved. 2 Objectives F To present the concept of view in 3D rendering process F To identify the parallel and perspective projections F To specify the viewing matrix F To specify the projection matrix F To apply Java 3D standard view model F To apply Java 3D compatibility mode view model F To apply picking in a 3D scene F To understand head-tracking in view models F To apply input devices, sensors, and head-tracking in Java 3D F To use the avatar in SimpleUniverse
Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved. 3 Parallel Projection
Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved. 4 Perspective Projection
Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved. 5 View Parameters F Projection – parallel or perspective projection. F View Plate – the window for the rendered image. It is usually a rectangular region. In a real camera the view plate corresponds to the film frame. F Field of view (fov) – the horizontal angle between the left and right plane of the frustum. The vertical field of view and diagonal field of view can be defined similarly. F Focal length – the distance between the view plate and the view point. F Aspect ratio – the ratio of width over length of the view planes. F Front clip plane – the front or near plane of the frustum. F Back clip plane – the back or far plane of the frustum.
Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved. 6 Projection Matrix Front plane Back plane
Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved. 7 Viewing Matrix F Viewpoint, view-reference point (vrp, eye) – the camera or eye position, the 3D point where the camera is located. F View center (look) – the center of view plate or the point that the eye is looking at. F View up direction (up) – the upward direction from a viewer’s perspective. F View plane – the plane of the projected image. F View plane normal (vpn) – the normal vector of the view plane.
Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved. 8 Java 3D View Model
Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved. 9 Configure a 3D View View class void setFieldOfView(double fov) void setFrontClipDistance(double d) void setBackClipDistance(double d) void setProjectionPolicy(int projection) void lookAt(Point3d eye, Point3d look, Vector3d up) Transform3D class
Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved. 10 The Compatibility Mode F A simple mode compatible with OpenGL F Static camera F Manual settings of fixed view parameters Source Run
Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved. 11 SimpleUniverse F Compatibility mode: false F Left projection: identity F Right projection: identity F vpc to ec transform: identity F Field of view: π/4 F Front clip distance: 0.1 F Back clip distance: 10 SourceRun
Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved. 12 Scene Graph
Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved. 13 Create Your Own Views SourceRun A view branch View view = new View(); view.setProjectionPolicy(View.PARALLEL_PROJECTION); ViewPlatform vp = new ViewPlatform(); view.addCanvas3D(cv); view.attachViewPlatform(vp); view.setPhysicalBody(new PhysicalBody()); view.setPhysicalEnvironment(new PhysicalEnvironment()); Transform3D trans = new Transform3D(); trans.lookAt(eye, center, vup); trans.invert(); TransformGroup tg = new TransformGroup(trans); tg.addChild(vp); BranchGroup bgView = new BranchGroup(); bgView.addChild(tg);
Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved. 14 Picking F Pick objects from the rendered image F Inverse of projection F Pre-images: a cone or a cylinder SceneGraphPath[] pickAll(PickShape pickShape) SceneGraphPath[] pickAllSorted(PickShape pickShape) SceneGraphPath pickAny(PickShape pickShape) SceneGraphPath pickClosest(PickShape pickShape)
Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved. 15 Picking SourceRun Picking example
Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved. 16 Head Tracking F Adjustment of view parameters following dynamic head position changes F Java 3D head tracking support –View –Sensor –PhysicalBody –PhysicalEnvironment SourceRun