DLP for Virtual Environments (II) Interaction between users and 3D objects Multiple Instances of 3D Objects Rotation/Orientation calculation.

Slides:



Advertisements
Similar presentations
Computer Graphics: 3D Transformations
Advertisements

Points, Vectors, Lines, Spheres and Matrices
Transformations Ed Angel Professor Emeritus of Computer Science
2D Geometric Transformations
This terms course Last term we both worked on learning 2 things –Processing –The concepts of graphics etc. This term will focus more on the basic concepts.
1 3D Vector & Matrix Chapter 2. 2 Vector Definition: Vector is a line segment that has the direction. The length of the line segment is called the magnitude.
John C. Hart CS 318 Interactive Computer Graphics
Mapping: Scaling Rotation Translation Warp
Informationsteknologi Wednesday, November 7, 2007Computer Graphics - Class 51 Today’s class Geometric objects and transformations.
Maths for Computer Graphics
Chapter 4.1 Mathematical Concepts
Chapter 4.1 Mathematical Concepts. 2 Applied Trigonometry Trigonometric functions Defined using right triangle  x y h.
CS 4731: Computer Graphics Lecture 6: Points, Scalars and Vectors Emmanuel Agu.
Now Playing: My Mathematical Mind Spoon From Gimme Fiction Released May 10, 2005.
CSCE 590E Spring 2007 Basic Math By Jijun Tang. Applied Trigonometry Trigonometric functions  Defined using right triangle  x y h.
3-D Geometry.
Copyright © 2014 John Wiley & Sons, Inc. All rights reserved.
Screw Rotation and Other Rotational Forms
Computer Graphics (Fall 2005) COMS 4160, Lecture 2: Review of Basic Math
3D Graphics Goal: To produce 2D images of a mathematically described 3D environment Issues: –Describing the environment: Modeling (mostly later) –Computing.
Geometric Objects and Transformations Geometric Entities Representation vs. Reference System Geometric ADT (Abstract Data Types)
Foundations of Computer Graphics (Fall 2012) CS 184, Lecture 2: Review of Basic Math
Geometric Intuition Randy Gaul. Vectors, Points and Basis Matrices Rotation Matrices Dot product and how it’s useful Cross product and how it’s useful.
Getting started © juhanita2015.
Mathematical Fundamentals
Computer Graphics: Programming, Problem Solving, and Visual Communication Steve Cunningham California State University Stanislaus and Grinnell College.
Vectors Jeff Chastine.
Game Physics – Part IV Moving to 3D
6.837 Linear Algebra Review Patrick Nichols Thursday, September 18, 2003.
Patrick Nichols Thursday, September 18, Linear Algebra Review.
Chapter 4.1 Mathematical Concepts
Virtual reality. Tasks 3D digital model from planes 3D digital model of existing objects Office work Field observations Solid modeling Photogrammetry.
CS 450: COMPUTER GRAPHICS QUATERNIONS SPRING 2015 DR. MICHAEL J. REALE.
Section 13.4 The Cross Product. Torque Torque is a measure of how much a force acting on an object causes that object to rotate –The object rotates around.
CS 480/680 Computer Graphics Transformations Dr. Frederick C Harris, Jr.
Computer Graphics Bing-Yu Chen National Taiwan University.
Dx = 2 dy = 3 Y X D Translation A translation is applied to an object by repositioning it along a straight-line path.
Week 5 - Wednesday.  What did we talk about last time?  Project 2  Normal transforms  Euler angles  Quaternions.
CS 325 Introduction to Computer Graphics 02 / 17 / 2010 Instructor: Michael Eckmann.
CS 376 Introduction to Computer Graphics 02 / 16 / 2007 Instructor: Michael Eckmann.
Math / Physics 101 GAM 376 Robin Burke Fall 2006.
Computer Graphics Group Script node Jiří Žára. Computer Graphics Group Contents 1.Script node 2.Motion generators 2Script node.
Learning Unity. Getting Unity
16/5/ :47 UML Computer Graphics Conceptual Model Application Model Application Program Graphics System Output Devices Input Devices API Function.
Matthew Christian. About Me Introduction to Linear Algebra Vectors Matrices Quaternions Links.
CS-498 Computer Vision Week 7, Day 2 Camera Parameters Intrinsic Calibration  Linear  Radial Distortion (Extrinsic Calibration?) 1.
CGDD 4003 THE MATH LECTURE (BOILED DOWN, YET LIGHTLY SALTED)
CO1301: Games Concepts Dr Nick Mitchell (Room CM 226) Material originally prepared by Gareth Bellaby.
UW EXTENSION CERTIFICATE PROGRAM IN GAME DEVELOPMENT 2 ND QUARTER: ADVANCED GRAPHICS Math Review.
Honours Graphics 2008 Session 2. Today’s focus Vectors, matrices and associated math Transformations and concatenation 3D space.
Composite 3D Transformations. Example of Composite 3D Transformations Try to transform the line segments P 1 P 2 and P 1 P 3 from their start position.
Computer Graphics I, Fall 2010 Transformations.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
© TMC Computer School HC20203 VRML HIGHER DIPLOMA IN COMPUTING Chapter 5 – Animation in VRML.
1 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Transformations Ed Angel Professor of Computer Science, Electrical and Computer Engineering,
Computer Graphics Mathematical Fundamentals Lecture 10 Taqdees A. Siddiqi
Computer Graphics Lecture 11 2D Transformations I Taqdees A. Siddiqi
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 1 Part 3 - Chapter 8 Linear Algebraic Equations and Matrices.
DLP for Virtual Environments (I)
Game Engine Architecture
CSE 167 [Win 17], Lecture 2: Review of Basic Math Ravi Ramamoorthi
Math Fundamentals Maths revisit.
Copyright © 2014 John Wiley & Sons, Inc. All rights reserved.
ECE 383/ME 442: Intro to Robotics and Automation
Physics 218 Lecture 15 Dr. David Toback Physics 218, Lecture XV.
(c) University of Wisconsin, CS559
UMBC Graphics for Games
Geometric Objects and Transformations (II)
Game Programming Algorithms and Techniques
Mathematics Vectors a b c LabRat Scientific © 2019.
Presentation transcript:

DLP for Virtual Environments (II) Interaction between users and 3D objects Multiple Instances of 3D Objects Rotation/Orientation calculation

Design 3D Objects with prototype Design a prototype Set an instantiated Object Use DEF to define the name of the object.

Example: Bus PROTO Bus [ exposedField SFVec3f translation exposedField SFRotation rotation ] { Transform { translation IS translation rotation IS rotation children [ ]}} Transform {children [ DEF bus1 Bus { translation rotation } ] }

Interaction: get viewpoint getSFVec3f(Viewpoint,position,X,Y,Z) getSFRotation(Viewpoint,orientation,X,Y,Z,R) getViewpointPosition(Viewpoint,X,Y,Z) getViewpointOrientation(Viewpoint,X,Y,Z,R) Problem: those get-predicates output only the values are either initial values or values are set by the set-predicates. They ignore the effects of the keyboard and the mouse navigation. Solution: Add proximity sensors.

Proximity Sensor DEF proxSensor ProximitySensor {center size enabled TRUE isActive TRUE} getSFVec3f(proxSensor,position,X,Y,Z) for getting the position of the viewpoint getSFRotation(proxSensor,orientation,X,Y,Z,R) for getting the orientation of the viewpoint Do not use setSFVec3f(proxSensor,position,X,Y,Z) and setSFRotation(proxSensor,orientation,X,Y,Z,R)

Example: Bus Driving

:-object wasp2 : [bcilib]. var url = './street/street5.wrl'. var timelimit = 300. main :-text_area(Browser), set_output(Browser), format('Loading street1 from ~w~n', [url]), loadURL(url), format('The bus1 is going to jump in front of you in 5 seconds,~n'), format('then you can drive the bus for ~w seconds~n', [timelimit]), delay(5000), jump(bus1), drive(bus1,timelimit). jump(Object) :-getSFVec3f(proxSensor,position,X,_Y,Z), Z1 is Z-5, setPosition(Object,X, 0.0,Z1).

drive(_,0):-!. drive(Object,N) :- N>0, N1 is N-1, format('time left: ~w seconds~n', [N]), delay(1000), getSFVec3f(proxSensor,position,X,_Y,Z), getSFRotation(proxSensor,orientation,_X2,Y2,_Z2,R2), setPosition(Object,X, 0.0,Z), R3 is sign(Y2)*R , setRotation(Object,0.0,1.0,0.0,R3), drive(Object,N1). :-end_object wasp2.

Rotations in VRML Rotation = Right-hand Rule

Rotation Calculation (I)

R3= Y2*R =sign(Y2)*R2+1.57

Mathematics for Virtual Environments Point: Vector = point2 – point1 Vector cross product: v1 X v2 point2 point1 vector v1 v2 v1 X v2 (Rotation axis: ) R

Cross Product The cross product of two vectors is perpendicular to both; the right hand rule picks the one out of two possible perpendicular directions.

Vector Math for 3D Computer Graphics · Chapter 0— Points in Space Chapter 0 ·Chapter 1— Vectors, Points, and DisplacementChapter 1 ·Chapter 2— Vector AdditionChapter 2 ·Chapter 3— Displacement VectorsChapter 3 ·Chapter 4— Length of VectorsChapter 4 ·Chapter 5— Direction of VectorsChapter 5 ·Chapter 6— Scaling and Unit VectorsChapter 6 ·Chapter 7— The Dot ProductChapter 7 ·Chapter 8— Length and the Dot ProductChapter 8 ·Chapter 9— The Angle between two Vectors.Chapter 9 ·Chapter 10— The Angle between 3D Vectors.Chapter 10 ·Chapter 11— Projecting one Vector onto Another.Chapter 11 ·Chapter 12— Vector Cross Product.Chapter 12 ·Chapter 13— Matrices and Simple Matrix Operations.Chapter 13 ·Chapter 14— Matrix-Column Matrix Multiplicaton.Chapter 14 ·Chapter 15— Matrix-Matrix MultiplicationChapter 15 ·Chapter 16— Identity Matrix and Matrix InverseChapter 16

Vectorlib in DLP vector_cross_product(V1, V2, V, R) direction_vector(position(X1,Y1,Z1),position(X2,Y2,Z2),vector (X,Y,Z)) vector_rotation(vector(X1,Y1,Z1),rotation(X,Y,Z,R),vector(X2, Y2,Z2)). position_rotation(position(X1,Y1,Z1),rotation(X,Y,Z,R),positio n(X2,Y2,Z2)

:-object wasp2v : [bcilib, vectorlib] look_in_direction(Object, InitVector,DesVector):- vector_cross_product(InitVector,DesVector,vector(X,Y,Z),R), setRotation(Object,X,Y,Z,R). drive(Object,N) :- N > 0, N1 is N-1, format('time left: ~w seconds~n', [N]), delay(1000), getSFVec3f(proxSensor,position,X,_Y,Z), getSFRotation(proxSensor,orientation,X2,Y2,Z2,R2), setPosition(Object,X, 0.0,Z), vector_rotation(vector(0,0,-1), rotation(X2,Y2,Z2,R2), vector(X3,Y3,Z3)), look_in_direction(Object,vector(1,0,0),vector(X3,Y3,Z3)), drive(Object,N1). :-end_object wasp2v.

Example: Soccer Kicking

:-object wasp3 : [bcilib]. var url = './soccer/soccer1b.wrl'. var timelimit = 300. main :-text_area(Browser), set_output(Browser), format('Load the game...~n'), loadURL(url), format('the game will start in 5 seconds,~n'), format('note that the total playing time period is ~w seconds,~n', [timelimit]), delay(5000), format('the game startup,~n'), play_ball(me, ball). play_ball(Agent, Ball) :- -- timelimit, timelimit > 0, !, format('time left: ~w seconds~n', [timelimit]), delay(800), near_ball_then_kick(Agent, Ball), play_ball(Agent, Ball). play_ball(_, _). /* capture-anything-else statement*/

near_ball_then_kick(Agent, Ball):- getViewpointPositionEx(Agent,X,_Y,Z), getPosition(Ball,X1,Y1,Z1), Xdif is X1-X,Zdif is Z1-Z, Dist is sqrt(Xdif*Xdif + Zdif*Zdif), Dist < 5, !, X2 is Xdif*3, Z2 is Zdif*3, X3 is X2 + X1, Z3 is Z2 + Z1, setPosition(Ball,X3,Y1,Z3). near_ball_then_kick(_, _). getViewpointPositionEx(_,X,Y,Z) :- getSFVec3f(proxSensor,position,X,Y,Z). getViewpointOrientationEx(_,X,Y,Z,R):- getSFRotation(proxSensor,orientation,X,Y,Z,R). :-end_object wasp3.

Example: Soccer Kicking 2

:-object wasp4 : [bcilib]. var url = './soccer/soccer2b.wrl'. var timelimit = 500. main :-text_area(Browser), set_output(Browser), format('Load the game...~n'), loadURL(url),..... play_ball(me, ball). play_ball(Agent, Ball) :- -- timelimit, timelimit > 0, !, format('time left: ~w seconds~n', [timelimit]), delay(800), look_at_ball(goalKeeper1,Ball), near_ball_then_kick(Agent, Ball), play_ball(Agent, Ball). play_ball(_, _).

near_ball_then_kick(Agent, Ball):- getViewpointPositionEx(Agent,X,_Y,Z), X3 is X2 + X1, Z3 is Z2 + Z1, setPosition(Ball,X3,Y1,Z3), checkBallPosition(Ball,X3,Y1,Z3). near_ball_then_kick(_, _). checkBallPosition(Ball, X, Y, Z):- getPosition(goalKeeper1,X1,_Y1,Z1), Xdif is X-X1, Zdif is Z-Z1, Dist is sqrt(Xdif*Xdif + Zdif*Zdif), Dist < 4, !, X2 is X - 8, format('The goalkeeper kicks the ball back~n'), setPosition(Ball,X2,Y,Z). checkBallPosition(_,_,_,_).

look_at_ball(Player,Ball):- getPosition(Player,X,_,Z), getPosition(Ball, X1,_,Z1), Xdif is X-X1, Xdif =\= 0.0, Zdif is Z1-Z, R is atan(Zdif/Xdif) - sign(Xdif)*1.571, setRotation(Player,0.0, 1.0, 0.0, R). look_at_ball(_,_). look_at_ball(Sportman,Ball):- getPosition(Sportman,_X,_,Z), getPosition(Ball, _X1,_,Z1), Z1 < Z, setRotation(Sportman,0.0, 1.0, 0.0, 3.14). look_at_ball(Sportman,Ball):- getPosition(Sportman,_X,_,Z), getPosition(Ball, _X1,_,Z1), Z1 > Z, setRotation(Sportman,0.0, 1.0, 0.0, 0.0). look_at_ball(_Player,_Ball):-! :-end_object wasp4.

Rotation Calculation (II) R is atan(Zdif/Xdif) - sign(Xdif)*1.57

R = 3.14 if Z > Z1 R = 0.0 if Z < Z1

:-object wasp4v : [bcilib, vectorlib] look_at_ball(Sportman,Ball):- getPosition(Sportman,X,_Y,Z), getPosition(Ball, X1,_Y1,Z1), direction_vector(position(X,0,Z), position(X1,0,Z1), vector(X2,Y2,Z2)), look_in_direction(Sportman,vector(0,0,1),vector(X2,Y2,Z2) ). :-end_obect wasp4v.

Exercises 1.Improve the example of ball kicking so that the soccer ball can continuously move to a new position. It would not just simply jump to the new position. 2. Design a DLP program to control the bus moving so that it can move along a route (which is defined by a set of facts, thus, a database). *3.(Bonus 5 marks)Improve the example of bus driving so that the user can start and stop the bus engine. Namely, the bus moves only after the engine starts, and the bus would not move if the engine stops.

Ball Moving

1.Move along a straight line constantly with Y- parameter unchanged. (interpolation) 2.Move along a curve in Y-dimension with a height. 3.Move subjected to the physical law of gravity and acceleration: x = x 0 +V x *t y = y 0 +V y *t-1/2*g*t*t z = z 0 +V z *t

Ball Moving: Interpolation :-object wasp5 : [bcilib]. var url = './soccer/soccer1b.wrl'. var timelimit = 500. var interpolation = 5. …… near_ball_then_kick(Agent, Ball):- getViewpointPositionEx(Agent,X,_Y,Z), getPosition(Ball,X1,Y1,Z1), Xdif is X1-X, Zdif is Z1-Z, Dist is sqrt(Xdif*Xdif + Zdif*Zdif), Dist < 5, !, X2 is Xdif*3, Z2 is Zdif*3, X3 is X2 + X1, Z3 is Z2 + Z1, move_to_position(Ball, position(X1,Y1,Z1), position(X3,Y1,Z3),interpolation). near_ball_then_kick(-,-).

move_to_position(Ball,_,position(X,Y,Z),0):- setPosition(Ball,X,Y,Z). move_to_position(Ball, position(X1,Y1,Z1), position(X2,Y2,Z2),C):- C1 is C-1, Xdif is X2 -X1, Zdif is Z2 -Z1, X is X1 + Xdif/C, Z is Z1 + Zdif/C, setPosition(Ball,X,Y1,Z), sleep(100), move_to_position(Ball,position(X,Y1,Z), position(X2,Y2,Z2),C1). :-end_object wasp5.

How to define a route

%route-point(route_id, point_index, X,Z) route_point(1,0,0,0):-!. route_point(1,1,100,0):-!. route_point(1,2,100,50):-!. route_point(1,3,-100,50):-!. route_point(1,4,-100,-50):-!. route_point(1,5,100,-50):-!. route_point(1,6,100,0):-!. route_point(1,7,0,0):-!. DLP programs would calculate the interpolations between two route points and set the correct rotation for moving the bus to the next route point.

Interpolation: based on the move_to_position example Rotation calculation: based on the look_in_direction example. Hints