computer science 385.3

11
Computer Science 385.3 Term 1, 2006 Tutoria l 1

Upload: maxwell-dickerson

Post on 31-Dec-2015

42 views

Category:

Documents


0 download

DESCRIPTION

Computer Science 385.3. Term 1, 2006. Tutorial 1. Tutorial Leader. Jeremy Long B. Sc. in Computer Science (2005) M. Sc. in Computer Science (2007, hopefully) Supervisor: Dr. David Mould Research Interests: Computer Graphics: NPR, procedural modeling, nonlinear raytracing. Contact Info: - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Computer Science 385.3

Computer Science 385.3

Term 1, 2006

Tutorial 1

Page 2: Computer Science 385.3

Tutorial Leader

● Jeremy Long

– B. Sc. in Computer Science (2005)

– M. Sc. in Computer Science (2007, hopefully)

● Supervisor: Dr. David Mould

– Research Interests:

● Computer Graphics: NPR, procedural modeling, nonlinear raytracing.

● Contact Info:

– Email: [email protected] (jsl847 at mail.usask.ca)

– Phone: 966-8654

– Office: IMG Lab, G60 Thorvaldson

Page 3: Computer Science 385.3

Tutorials

● Tutorial Sections:– Thursday – 4:00-5:20, S311.

– Friday – 1:30-3:00, S311.

● 5 Tutorials throughout the term

Page 4: Computer Science 385.3

Assignment 1 – Pool Table Simulation

-Part 1: The Pool Balls-Part 2: User Input-Part 3: Simulation Step-Part 4: Collisions-Part 5: Matrix Math

Tutorial Outline

Page 5: Computer Science 385.3

Assignment 1 – Pool Table Simulation

Part 1 – Pool Balls

ball{

radius; // Radius of the ball

positionX, positionY; // 2-dimensional coordinatesvelocityX, velocityY; // velocity broken down in x and yactive; // indicates whether this ball is still in play

}

Rendering Circles

360 degrees = 2pi radians

CircleX = positionX + cos(Radians) * radius

CircleY = positionY + sin(Radians) * radius

Page 6: Computer Science 385.3

Assignment 1 – Pool Table Simulation

Part 2 – User InputmouseFunction( int button, int state, int sx, int sy)

{// You should first convert Screen Coordinates to world coordinates

if (left button is pushed down)

{if (cueBall is near click coordinates)

{

get ball coordinates

mouseDown = true

}}if (left button is released)

{

if (mouseDown)

{set cueBall velocity based on new mouse position

}

}}

Page 7: Computer Science 385.3

Assignment 1 – Pool Table Simulation

Part 3 – Simulation Step

The simulation step will be done in the program’s idle function, and will

need to perform the following tasks.

-Check if any active balls are in a pocket.

-Check if any active balls have collided with the walls or other active balls.

-Update the locations of the active balls based on their velocity.

-Apply friction to the velocities of all active balls.

Page 8: Computer Science 385.3

Assignment 1 – Pool Table Simulation

Part 4 – CollisionsOnce we have detected a collision, how do we resolve it?

-Collisions are elastic, so momentum and velocity is preserved.

Collisions with the Wall:-Reverse the velocity component perpendicular to the wall in question.

Collisions with other balls:-More complicated – see Assignment 1 description for diagrams.

Page 9: Computer Science 385.3

Assignment 1 – Pool Table Simulation

Part 4 – Collisionsfor each ball in the collision

{

normalize the current ball's velocity vector – v1 (each component/the vector's length)

find vector pointing to the other ball in the collision - v2

normalize each component of v2

get the cosine by taking the dot product of v1 and v2

find new horizontal vector h1

reposition the vertical vector v0 based on h1

setVelocity(Hx1 + Vx0, Hy1 + Vy0) // set x and y velocities based on vectors calculated.

}

Page 10: Computer Science 385.3

Assignment 1 – Pool Table Simulation

Part 5 – Math Questions

Two translation matrices:

1 0 0 x

0 1 0 y

0 0 1 z

0 0 0 1

1 0 0 a

0 1 0 b

0 0 1 c

0 0 0 1

*

1 0 0 x

0 1 0 y

0 0 1 z

0 0 0 1

1 0 0 a

0 1 0 b

0 0 1 c

0 0 0 1

* =

Rotation: cosA sinA

-sinA cosA

Page 11: Computer Science 385.3

Questions

Special thanks to our dark sponsor, Coca-Cola.