Simulation Essentials PowerPoint PPT Presentation

presentation player overlay
1 / 17
About This Presentation
Transcript and Presenter's Notes

Title: Simulation Essentials


1
Simulation Essentials
  • Overview
  • World System of Coordinates
  • Device System of Coordinates
  • Transformation Equations
  • Projectile Motion Equations
  • Boundaries
  • Randomization, Timer
  • Keyboard Handling

2
PHYSICS
159.234
PROJECTILE MOTION
Time, Initial Velocity, Mass, pull of gravity
Air resistance, property of material, etc.
1 ter

3
Transformation Equations
159.234
WORLD-to-DEVICE COORDINATES
100,000,000 miles x 500,000 miles
1280 x 1024 pixels
y
0
x
(Xworld,Yworld)
(XDevice,YDevice)
x
y
0
World System of Coordinates
Device System of Coordinates
4
Transformation Equations
159.234
From World Coordinates to Device Coordinates
How?
Scaling from some very big or very small values
to the boundaries of the computer screen
e.g. (124,075,454 , 765,454,012) to (345,
675)
5
World-to-Device Coordinates
159.234
TRANSFORMATION EQUATIONS
6
World-to-Device Coordinates
159.234
TRANSFORMATION EQUATIONS
7
Projectile Motion
159.234
PHYSICS EQUATIONS
where g 9.8 m/sec.2 pull of gravity Vo
in m/sec. initial velocity t in sec.
time
8
World Boundaries
159.234
SETTING THE BOUNDARIES
where ?85 degrees
where ?45 degrees
Time of flight from take-off to landing
9
World Boundaries
159.234
SETTING THE BOUNDARIES
Use the upper-left and bottom-right coordinates
to set the boundaries
y
0
x
(Xworld,Yworld)
(XDevice,YDevice)
x
y
0
Top-left x1, y1 Bottom-right x2, y2
10
Projectile Motion
159.234
PUTTING THE PIECES TOGETHER
circle(x, y, radius)
// InitGraphics here // InitBoundaries
here t0.0 while(t lt tf)
cleardevice() setcolor(RED) circle
(Xdev(x(t, Vo, Theta)),Ydev(y(t, Vo, Theta)),
12) tttinc
World-to-Device Transformation Function
Physics Equation for x
11
System of Coordinates
159.234
EFFECTS OF CHANGING THE BOUNDARIES
What happens if we switch the values for
DeviceBound x2 and DeviceBound x1?
What happens if we double all the maximum values
for the WorldBound Coordinates?
12
Element of Surprise
159.234
rand()
generates a pseudorandom number - returns int
srand(time(NULL))
int RandomVal(int min, int max) return (min
(rand() ((max-min)1) ))
13
Element of Surprise
159.234
srand()
Seed for random-number generation
Seed the random-number generator with current
time so that  the numbers will be different every
time we run.   srand( (unsigned)time( NULL ) )
  / Display 10 numbers. /   for( i 0   i lt
10i )      printf( "  6d\n", rand() )
14
Element of Surprise
159.234
rand()
generates a pseudorandom number - returns int
int RandomVal(int min, int max) return (min
(rand() ((max-min)1) ))
15
Element of Surprise
159.234
rand()
float RandomVal(float min, float max) float
r r (float)rand()/RAND_MAX r min
(r(max-min)) return r
16
Keyboard Handling
159.234
GetAsyncKeyState
The GetAsyncKeyState function determines whether
a key is up or down at the time the function is
called, and whether the key was pressed after a
previous call to GetAsyncKeyState.
SHORT GetAsyncKeyState( int vKey ) // vKey -
virtual-key code
Virtual-key code e.g. vk_shift vk_control
To find other pre-defined constants Using
google, type the following keywords msdn
vk_shift
17
Keyboard Handling
159.234
GetAsyncKeyState
void MoveSprite() if(GetAsyncKeyState(VK_UP)
lt0) SpriteY SpriteY - 2 //up
outtext("UP") if(GetAsyncKeyState(VK_DOWN
)lt0) SpriteY SpriteY 2 //down
outtext("DOWN") .
To find other pre-defined constants Using
google, type the following keywords msdn
vk_shift
Write a Comment
User Comments (0)
About PowerShow.com