1 / 11

Computer Science 385.3

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:

Download Presentation

Computer Science 385.3

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Computer Science 385.3 Term 1, 2006 Tutorial 1

  2. 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: jsl847@mail.usask.ca (jsl847 at mail.usask.ca) • Phone: 966-8654 • Office: IMG Lab, G60 Thorvaldson

  3. Tutorials • Tutorial Sections: • Thursday – 4:00-5:20, S311. • Friday – 1:30-3:00, S311. • 5 Tutorials throughout the term

  4. Assignment 1 – Pool Table Simulation Tutorial Outline -Part 1: The Pool Balls -Part 2: User Input -Part 3: Simulation Step -Part 4: Collisions -Part 5: Matrix Math

  5. Assignment 1 – Pool Table Simulation Part 1 – Pool Balls ball{ radius; // Radius of the ball positionX, positionY; // 2-dimensional coordinates velocityX, velocityY; // velocity broken down in x and y active; // indicates whether this ball is still in play} RenderingCircles 360 degrees = 2pi radians CircleX = positionX + cos(Radians) * radius CircleY = positionY + sin(Radians) * radius

  6. Assignment 1 – Pool Table Simulation Part 2 – User Input mouseFunction( 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 } }}

  7. 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.

  8. Assignment 1 – Pool Table Simulation Part 4 – Collisions Once 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.

  9. Assignment 1 – Pool Table Simulation Part 4 – Collisions for 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.}

  10. Assignment 1 – Pool Table Simulation Part 5 – Math Questions Twotranslation matrices: 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 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 = * * cosA sinA -sinA cosA Rotation:

  11. Questions Special thanks to our dark sponsor, Coca-Cola.

More Related