DLP for Virtual Environments II - PowerPoint PPT Presentation

1 / 35
About This Presentation
Title:

DLP for Virtual Environments II

Description:

DLP for Virtual Environments (II) Interaction between users and ... format('The goalkeeper kicks the ball back~n'), setPosition(Ball,X2,Y,Z). checkBallPosition ... – PowerPoint PPT presentation

Number of Views:39
Avg rating:3.0/5.0
Slides: 36
Provided by: faculte150
Category:

less

Transcript and Presenter's Notes

Title: DLP for Virtual Environments II


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

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

3
Example Bus
PROTO Bus exposedField SFVec3f
translation 0 0 0 exposedField SFRotation
rotation 0 1 0 0 Transform translation IS
translation rotation IS rotation children
...... Transform children DEF bus1 Bus
translation -5 0 -1.5 rotation 0 1 0 0
4
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.

5
Proximity Sensor
  • DEF proxSensor ProximitySensor center 0 0 0
  • size 1000 1000 1000 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)

6
Example Bus Driving
7
-object wasp2 bcilib. var url
'./street/street5.wrl'. var timelimit
300. main -text_area(Browser), set_output(Brow
ser), format('Loading street1 from wn',
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 secondsn', 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).
8
drive(_,0)-!. drive(Object,N) - Ngt0, N1 is
N-1, format('time left w secondsn', N),
delay(1000), getSFVec3f(proxSensor,pos
ition,X,_Y,Z), getSFRotation(proxSensor,or
ientation,_X2,Y2,_Z2,R2),
setPosition(Object,X, 0.0 ,Z), R3 is
sign(Y2)R2 1.571, setRotation(Object,0.0
,1.0,0.0,R3), drive(Object,N1). -end_object
wasp2.
9
Rotations in VRML
Rotation lt1, 0, 0, 1.57gt
Angle in radians
The axis of rotation
1
Right-hand Rule
10
Rotation Calculation (I)
X
-Z
11
Rotation Calculation (I)
R3 Y2R2 1.57 sign(Y2)R21.57
12
Mathematics for Virtual Environments
v1 X v2 (Rotation axisltx,y,zgt)
  • Point ltX,Y,Zgt
  • Vector point2 point1
  • Vector cross product v1 X v2

v2
point2
R
vector
point1
v1
13
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.
14
Vector Math for 3D Computer Graphics
http//chortle.ccsu.edu/vectorLessons/vectorIndex.
html
Chapter 0 Points in Space Chapter 1
Vectors, Points, and Displacement Chapter 2
Vector Addition Chapter 3 Displacement
Vectors Chapter 4 Length of
Vectors Chapter 5 Direction of
Vectors Chapter 6 Scaling and Unit
Vectors Chapter 7 The Dot Product Chapter
8 Length and the Dot Product Chapter 9 The
Angle between two Vectors. Chapter 10 The
Angle between 3D Vectors. Chapter 11
Projecting one Vector onto Another. Chapter
12 Vector Cross Product. Chapter 13
Matrices and Simple Matrix Operations. Chapter
14 Matrix-Column Matrix Multiplicaton. Chapte
r 15 Matrix-Matrix Multiplication Chapter
16 Identity Matrix and Matrix Inverse
15
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),position(X2,Y2,Z2)

16
-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(Ob
ject,N) - N gt 0, N1 is N-1, format('time
left w secondsn', N), delay(1000), getSFVec
3f(proxSensor,position,X,_Y,Z), getSFRotation(pro
xSensor,orientation,X2,Y2,Z2,R2), setPosition(Obj
ect,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.
17
Example Soccer Kicking
18
-object wasp3 bcilib. var url
'./soccer/soccer1b.wrl'. var timelimit
300. main -text_area(Browser), set_output(Brows
er), 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(Age
nt, Ball) - -- timelimit, timelimit gt 0,
!, format('time left w secondsn',
timelimit), delay(800), near_ball_then_kick(Ag
ent, Ball), play_ball(Agent, Ball). play_ball(_,
_). / capture-anything-else statement/
19
near_ball_then_kick(Agent, Ball)- getViewpointPo
sitionEx(Agent,X,_Y,Z), getPosition(Ball,X1,Y1,Z1
), Xdif is X1-X, Zdif is Z1-Z, Dist is
sqrt(XdifXdif ZdifZdif), Dist lt 5, !, X2
is Xdif3, Z2 is Zdif3, X3 is X2 X1, Z3 is
Z2 Z1, setPosition(Ball,X3,Y1,Z3). near_ball_t
hen_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.
20
(No Transcript)
21
Example Soccer Kicking 2
22
-object wasp4 bcilib. var url
'./soccer/soccer2b.wrl'. var timelimit
500. main -text_area(Browser), set_output(Brow
ser), format('Load the game ...n'), loadURL(ur
l), ..... play_ball(me, ball). play_ball(Agent
, Ball) - -- timelimit,
timelimit gt 0, !, format('time left w
secondsn', timelimit), delay(800), look_at_ba
ll(goalKeeper1,Ball), near_ball_then_kick(Agent,
Ball), play_ball(Agent, Ball). play_ball(_,
_).
23
near_ball_then_kick(Agent, Ball)- getViewpointPo
sitionEx(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(XdifXdif
ZdifZdif), Dist lt 4, !, X2 is X -
8, format('The goalkeeper kicks the ball
backn'), setPosition(Ball,X2,Y,Z). checkBallPos
ition(_,_,_,_).
24
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(P
layer,0.0, 1.0, 0.0, R). look_at_ball(_,_). loo
k_at_ball(Sportman,Ball)- getPosition(Sportman,_
X,_,Z), getPosition(Ball, _X1,_,Z1), Z1 lt
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 gt Z, setRotation(Sportman,0.0,
1.0, 0.0, 0.0). look_at_ball(_Player,_Ball)-!.
..... -end_object wasp4.
25
Rotation Calculation (II)
R is atan(Zdif/Xdif) - sign(Xdif)1.57
26
R 3.14 if Z gt Z1 R 0.0 if Z lt Z1
27
-object wasp4v bcilib, vectorlib. ...... lo
ok_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,vec
tor(0,0,1),vector(X2,Y2,Z2)). -end_obect
wasp4v.
28
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.

29
Ball Moving
30
Ball Moving
  • Move along a straight line constantly with
    Y-parameter unchanged. (interpolation)
  • Move along a curve in Y-dimension with a height.
  • Move subjected to the physical law of gravity and
    acceleration
  • x x0Vxt
  • y y0Vyt-1/2gtt
  • z z0Vzt

31
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), ge
tPosition(Ball,X1,Y1,Z1), Xdif is X1-X, Zdif is
Z1-Z, Dist is sqrt(XdifXdif ZdifZdif), Dist
lt 5, !, X2 is Xdif3, Z2 is Zdif3, X3 is
X2 X1, Z3 is Z2 Z1, move_to_position(Bal
l, position(X1,Y1,Z1),
position(X3,Y1,Z3),interpolation). near_ball_then
_kick(-,-).
32
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,pos
ition(X,Y1,Z),
position(X2,Y2,Z2),C1). -end_object wasp5.
33
How to define a route
34
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.
35
Hints
Interpolation based on the move_to_position
example Rotation calculation based on the
look_in_direction example.
Write a Comment
User Comments (0)
About PowerShow.com