How To Draw A Billiards Ball In Gta 3D With Texture Mapping (Gta 3) On A Computer Or 2D Or Gta 2D (Gt) On Your Computer Or Computer Or Your Computer (Or Your Computer)

Similar documents
Adding vectors We can do arithmetic with vectors. We ll start with vector addition and related operations. Suppose you have two vectors

Two vectors are equal if they have the same length and direction. They do not

CHAPTER 8, GEOMETRY. 4. A circular cylinder has a circumference of 33 in. Use 22 as the approximate value of π and find the radius of this cylinder.

11.1. Objectives. Component Form of a Vector. Component Form of a Vector. Component Form of a Vector. Vectors and the Geometry of Space

Solving Simultaneous Equations and Matrices

TWO-DIMENSIONAL TRANSFORMATION

One advantage of this algebraic approach is that we can write down

Solutions to old Exam 1 problems

Pro/ENGINEER Wildfire 4.0 Basic Design

Geometry of Vectors. 1 Cartesian Coordinates. Carlo Tomasi

Linear algebra and the geometry of quadratic equations. Similarity transformations and orthogonal matrices

Image Processing and Computer Graphics. Rendering Pipeline. Matthias Teschner. Computer Science Department University of Freiburg

ART 269 3D Animation Fundamental Animation Principles and Procedures in Cinema 4D

Solutions for Review Problems

CS 4204 Computer Graphics

521493S Computer Graphics. Exercise 2 & course schedule change

Review Sheet for Test 1

Copyright 2011 Casa Software Ltd. Centre of Mass

Algebra Geometry Glossary. 90 angle

3D Viewing. Chapter 7. Projections. 3D clipping. OpenGL viewing functions and clipping planes

INTRODUCTION TO RENDERING TECHNIQUES

Geometry Notes PERIMETER AND AREA

Sandia High School Geometry Second Semester FINAL EXAM. Mark the letter to the single, correct (or most accurate) answer to each problem.

Blender Notes. Introduction to Digital Modelling and Animation in Design Blender Tutorial - week 9 The Game Engine

ABERLINK 3D MKIII MEASUREMENT SOFTWARE

Monash University Clayton s School of Information Technology CSE3313 Computer Graphics Sample Exam Questions 2007

The Vector or Cross Product

discuss how to describe points, lines and planes in 3 space.

THREE DIMENSIONAL GEOMETRY

A Short Introduction to Computer Graphics

Solutions to Practice Problems for Test 4

Introduction to CATIA V5

Additional Topics in Math

Angle - a figure formed by two rays or two line segments with a common endpoint called the vertex of the angle; angles are measured in degrees

Fundamentals of Computer Animation

Determine whether the following lines intersect, are parallel, or skew. L 1 : x = 6t y = 1 + 9t z = 3t. x = 1 + 2s y = 4 3s z = s

Vector Algebra II: Scalar and Vector Products

Exam 1 Sample Question SOLUTIONS. y = 2x

Figure 1.1 Vector A and Vector F

Section 11.1: Vectors in the Plane. Suggested Problems: 1, 5, 9, 17, 23, 25-37, 40, 42, 44, 45, 47, 50

Solutions to Practice Problems

Introduction to Computer Graphics

FINAL EXAM SOLUTIONS Math 21a, Spring 03

Section 1.1. Introduction to R n

Name Class. Date Section. Test Form A Chapter 11. Chapter 11 Test Bank 155

Equations Involving Lines and Planes Standard equations for lines in space

Vector Notation: AB represents the vector from point A to point B on a graph. The vector can be computed by B A.

Section 9.1 Vectors in Two Dimensions

13.4 THE CROSS PRODUCT

Concepts in Calculus III

Angles that are between parallel lines, but on opposite sides of a transversal.

Teacher Page Key. Geometry / Day # 13 Composite Figures 45 Min.

Conjunction is true when both parts of the statement are true. (p is true, q is true. p^q is true)

We can display an object on a monitor screen in three different computer-model forms: Wireframe model Surface Model Solid model

Transformations in the pipeline

Math 241, Exam 1 Information.

Section 16: Neutral Axis and Parallel Axis Theorem 16-1

Android and OpenGL. Android Smartphone Programming. Matthias Keil. University of Freiburg

Geometry in architecture and building

CATIA Wireframe & Surfaces TABLE OF CONTENTS

Creating Your Own 3D Models

Geometry Regents Review

Conjectures. Chapter 2. Chapter 3

CATIA Functional Tolerancing & Annotation TABLE OF CONTENTS

Glencoe. correlated to SOUTH CAROLINA MATH CURRICULUM STANDARDS GRADE 6 3-3, , , 4-9

28 CHAPTER 1. VECTORS AND THE GEOMETRY OF SPACE. v x. u y v z u z v y u y u z. v y v z

12-1 Representations of Three-Dimensional Figures

2nd Semester Geometry Final Exam Review

MATH 275: Calculus III. Lecture Notes by Angel V. Kumchev

Self-Positioning Handheld 3D Scanner

Curves and Surfaces. Goals. How do we draw surfaces? How do we specify a surface? How do we approximate a surface?

Chapter 8 Geometry We will discuss following concepts in this chapter.

CIRCLE COORDINATE GEOMETRY

Basic Understandings

High School Geometry Test Sampler Math Common Core Sampler Test

ME 111: Engineering Drawing

Solutions to Homework 10

Activities Grades K 2 EXPLORING TESSELLATIONS. Background: What is a tessellation? Part One: Tessellating with One Shape

How To Learn To Understand And Understand The Math Of The Year

The Rocket Steam Locomotive - Animation

How To Draw A Circle Of Radius 1 On A Computer (For A Computer)

Aston University. School of Engineering & Applied Science

Objectives After completing this section, you should be able to:

Pro/ENGINEER Wildfire 5.0 Introduction to Surface Modeling

Platonic Solids. Some solids have curved surfaces or a mix of curved and flat surfaces (so they aren't polyhedra). Examples:

Selected practice exam solutions (part 5, item 2) (MAT 360)

Everyday Mathematics CCSS EDITION CCSS EDITION. Content Strand: Number and Numeration

AP Physics - Vector Algrebra Tutorial

This makes sense. t /t 2 dt = 1. t t 2 + 1dt = 2 du = 1 3 u3/2 u=5

H.Calculating Normal Vectors

Everyday Mathematics GOALS

Line Segments, Rays, and Lines

Chapter 2 Lead Screws

Sample Test Questions

Number Sense and Operations

Unified Lecture # 4 Vectors

Geometry Notes VOLUME AND SURFACE AREA

2006 Geometry Form A Page 1

Designing and Drawing a Sprocket Visualizing ideas through the creation of CAD solid models is a key engineering skill.

Geometry and Measurement

Transcription:

Pool Billiard An OpenGL-based billiard simulation Stefan HUBER Kamran SAFDAR Andreas SCHRÖCKER Fachbereich Computerwissenschaften Universität Salzburg June 10, 2009 S. Huber, K. Safdar, A. Schröcker: Pool Billiard, An OpenGL-based billiard simulation 1/34

Table of Contents 1 Modelling the Balls 2 Modelling the Table 3 Force Simulation 4 Viewing 5 Animation 6 Control S. Huber, K. Safdar, A. Schröcker: Pool Billiard, An OpenGL-based billiard simulation 2/34

Outline 1 Modelling the Balls An Introduction to Texture Mapping What is Texture Mapping? 2D Texture Mapping Texture Mapping a Sphere Texturing the Billiard Balls Drawing the Billiard Balls using OpenGL 2 Modelling the Table 3 Force Simulation 4 Viewing 5 Animation 6 Control S. Huber, K. Safdar, A. Schröcker: Pool Billiard, An OpenGL-based billiard simulation 3/34

The Ball Rendered using a sphere (glusphere) with unit radius, 50 slices and 50 stacks. A texture image is wrapped around it to give it a look of billiard ball. Figure: Wire Sphere Figure: Texture image Figure: Textured Sphere S. Huber, K. Safdar, A. Schröcker: Pool Billiard, An OpenGL-based billiard simulation 4/34

Texture Mapping Mapping of a function, called a texture map, onto a surface. Can be understood as gluing a 2D image onto the surface of a 3D object. Pioneered by Edwin Catmull in 1974. Can be used to enhance the aesthetic appearance of an object at a relatively small computational cost. Figure: A 2D image mapped onto a 3D cylinder. Image source: http://prosjekt.ffi.no/unik-4660/ lectures04/chapters/basic.html S. Huber, K. Safdar, A. Schröcker: Pool Billiard, An OpenGL-based billiard simulation 5/34

2D Texture Mapping The 2D texture space is defined in terms of parameters s and t each ranging from 0 to 1. For each point in the 3D object space, a corresponding point in the 2D texture space, called a texel, is mapped. While rendering the 3D object, each point (x,y,z) is assigned a color value computed from the corresponding 2D texel value (s, t). S. Huber, K. Safdar, A. Schröcker: Pool Billiard, An OpenGL-based billiard simulation 6/34

Geometry of a Sphere Geometrically stating, a sphere with radius r centred at C(x c,y c,z c ) is the locus of points P i (x,y,z),(0 i n), such that z t r P (x x c ) 2 +(y y c ) 2 +(z z c ) 2 = r 2 C For any point P(x,y,z) on surface of the sphere, let s be the angle from +x-axis to CP, and t be the angle from +z-axis to CP, such that (0 s 2π) and (0 t π). x s P y S. Huber, K. Safdar, A. Schröcker: Pool Billiard, An OpenGL-based billiard simulation 7/34

Geometry of a Sphere The parametric representation can be explained mathematically as: z x = x c + r sint coss y = y c + r sint sins z = z c + r cost C t r P with s [0,2π] and t [0,π] So, if we know the coordinates of a point P(x,y,z) on surface of the sphere, then we can easily find out the values of parameters s and t. x s P y S. Huber, K. Safdar, A. Schröcker: Pool Billiard, An OpenGL-based billiard simulation 8/34

Billiard Ball Textures The textures are 512 256 RAW images. The lines marked as North pole and South pole are mapped onto single points at the poles. 0 0 s 1 North pole t 256 1 512 South pole S. Huber, K. Safdar, A. Schröcker: Pool Billiard, An OpenGL-based billiard simulation 9/34

Mapping the Ball Textures Texture coordinates are assigned such that: x z t = 0 North pole y s = 0.5 s = 0.00 at y = +r s = 0.25 at x = +r s = 0.50 at y = r s = 0.75 at x = r s = 1.00 at y = +r t = 0.0 at z = r t = 1.0 at z = +r s = 1 +y s = 0 +x South pole t = 1 +z S. Huber, K. Safdar, A. Schröcker: Pool Billiard, An OpenGL-based billiard simulation 10/34

The Basic Algorithm Draw the Billiard Ball Load the texture map in memory Create a quadric object Enable texturing of the quadric object Draw a quadric Sphere, generate texture coordinates for it as per the scheme already known and load the texels Do garbage collection and house keeping S. Huber, K. Safdar, A. Schröcker: Pool Billiard, An OpenGL-based billiard simulation 11/34

Drawing the Billiard Balls using OpenGL 1 void DrawBall () 2 { 3 GLuint texture_map ; 4 GLUquadric * qobj = glunewquadric (); 5 6 texture_map = LoadTextureRAW (" textures /2. raw", true, 512, 256); 7 glenable ( GL_TEXTURE_2D ); 8 glbindtexture ( GL_TEXTURE_2D, texture_map ); 9 gluquadrictexture ( qobj, GL_TRUE); 0 glusphere (qobj,1,50,50); 1 gludeletequadric ( qobj); 2 gldeletetextures ( 1, & texture_map ); 3 gldisable ( GL_TEXTURE_2D ); 4 } S. Huber, K. Safdar, A. Schröcker: Pool Billiard, An OpenGL-based billiard simulation 12/34

Outline 1 Modelling the Balls 2 Modelling the Table Drawing the Table Texturing the Table 3 Force Simulation 4 Viewing 5 Animation 6 Control S. Huber, K. Safdar, A. Schröcker: Pool Billiard, An OpenGL-based billiard simulation 13/34

Structure of the Table quad strip quad strip The Table is axis aligned. Rectangular planes GL QUADS Pockets GL QUAD STRIPS GL TRIANGLE FAN GL TRIANGLES rectangle rectangle trapezoid triangle quad strip trapezoid triangle triangle fan S. Huber, K. Safdar, A. Schröcker: Pool Billiard, An OpenGL-based billiard simulation 14/34

Drawing the Edge Draw a half of and a quarter of a circle with brute-force scan-conversion algorithm Save the points in two arrays Connect the points with GL QUAD STRIPS For the hole: Draw an arc and use GL TRIANGLE FAN S. Huber, K. Safdar, A. Schröcker: Pool Billiard, An OpenGL-based billiard simulation 15/34

Drawing the Legs A cylinder is drawn void glucylinder() And closed with void gludisk() S. Huber, K. Safdar, A. Schröcker: Pool Billiard, An OpenGL-based billiard simulation 16/34

Symmetric Construction of the Table S. Huber, K. Safdar, A. Schröcker: Pool Billiard, An OpenGL-based billiard simulation 17/34

Full Table We make use of the symmetry in the table s geometry. One quarter of a table is drawn 4 times with glscalef(). S. Huber, K. Safdar, A. Schröcker: Pool Billiard, An OpenGL-based billiard simulation 18/34

Table Texture Two different raw files: Wooden texture and green cloth texture The texture coordinates are specified with gltexcoord2d(u,v) For GL QUADS: Set u,v to (0.0,0.0), (0.0,1.0), (1.0,0.0), (1.0,1.0) For the rest: Calculate u,v so that it looks properly S. Huber, K. Safdar, A. Schröcker: Pool Billiard, An OpenGL-based billiard simulation 19/34

Outline 1 Modelling the Balls 2 Modelling the Table 3 Force Simulation 4 Viewing 5 Animation 6 Control S. Huber, K. Safdar, A. Schröcker: Pool Billiard, An OpenGL-based billiard simulation 20/34

Force Simulation Orthogonal projection for drawing in 2D glortho(0, 10.0, 0.0, 10.0, -1, 1); We used three GL QUADS with different blending functions Black background: glblendfunc(gl ZERO,GL ZERO) Color slide: glblendfunc(gl ONE, GL ZERO) Transparent slide: glblendfunc(gl DST COLOR, GL SRC ALPHA) S. Huber, K. Safdar, A. Schröcker: Pool Billiard, An OpenGL-based billiard simulation 21/34

Outline 1 Modelling the Balls 2 Modelling the Table 3 Force Simulation 4 Viewing Camera Movement 5 Animation 6 Control S. Huber, K. Safdar, A. Schröcker: Pool Billiard, An OpenGL-based billiard simulation 22/34

A Top View S. Huber, K. Safdar, A. Schröcker: Pool Billiard, An OpenGL-based billiard simulation 23/34

A Strike Direction View S. Huber, K. Safdar, A. Schröcker: Pool Billiard, An OpenGL-based billiard simulation 24/34

Looking at the Center of the Table S. Huber, K. Safdar, A. Schröcker: Pool Billiard, An OpenGL-based billiard simulation 25/34

Setting Camera in Display Function 1 switch ( ncamerastate ) 2 { 3 case CAM_SHOOTING : 4 glulookat ( eye_x, eye_y, eye_z, 5 arrballs [0]. pos.x,0.285, arrballs [0]. pos.z, 6 0.0, 1.0, 0.0); 7 break; 8 9 case CAM_OVERVIEW : 0 glulookat (0,35,0, 0,0,0, 1.0, 0.0, 0.0); 1 break; 2 3 case CAM_CENTER : 4 glulookat ( eye_x, eye_y, eye_z, 0,0,0, 0.0, 1.0, 0.0); 5 break; 6 } S. Huber, K. Safdar, A. Schröcker: Pool Billiard, An OpenGL-based billiard simulation 26/34

Outline 1 Modelling the Balls 2 Modelling the Table 3 Force Simulation 4 Viewing 5 Animation Movement and Friction Rotation of Balls Collision with the Cushion Collision of Balls 6 Control S. Huber, K. Safdar, A. Schröcker: Pool Billiard, An OpenGL-based billiard simulation 27/34

Movement and Rotation of Balls Movement: Adding a constant vector to the position. Friction: Simulated by subtracting a part of the movement vector. S. Huber, K. Safdar, A. Schröcker: Pool Billiard, An OpenGL-based billiard simulation 28/34

Rotation of Balls In real life, movement of a ball is understood as: Displacement from start position Revolution around its center in the direction of movement Rotation matrix is stored for every ball and applied when drawing - on every step of animation a new rotation matrix is multiplied on this stored matrix x 2 (1 c) + c xy(1 c) zs xz(1 c) + ys 0 yx(1 c) + zs y 2 (1 c) + c yz(1 c) xs 0 xz(1 c) ys yz(1 c) + xs z 2 (1 c) + c 0 0 0 0 1 c = cos(angle),s = sin(angle), (x,y,z) = 1 S. Huber, K. Safdar, A. Schröcker: Pool Billiard, An OpenGL-based billiard simulation 29/34

Collision with the Cushion The ball is reflected back when it strikes the cushion. Reflection is calculated by changing the sign of x or z component of the movement vector (remember, cushions are parallel to x or z axis). A R S. Huber, K. Safdar, A. Schröcker: Pool Billiard, An OpenGL-based billiard simulation 30/34

Collision of Balls -(a-b) A a b B (a-b) S. Huber, K. Safdar, A. Schröcker: Pool Billiard, An OpenGL-based billiard simulation 31/34

Collision of Balls 1 void ball_check_collision (struct BALL* b1, struct BALL* b2) { 2 GLdouble b1b2_norm ; 3 Vertex v1, v2, vdiff, b1b2; 4 5 vec_diff (&b2 ->pos, &b1 ->pos, &b1b2); 6 b1b2_norm = norm (& b1b2); 7 if ( b1b2_norm < BALL_DIAMETER ) { 8 GLdouble s1 = vec_dotp (& b1 ->move, & b1b2)/ b1b2_norm ; 9 GLdouble s2 = vec_dotp (& b2 ->move, & b1b2)/ b1b2_norm ; 0 GLdouble sd = fabs(s1 - s2); 1 2 vec_mult (& b1b2, 1/ b1b2_norm, & b1b2); // build unit-vector of b1b2 3 4 vec_mult (&b1b2, -sd, &v1); 5 vec_mult (&b1b2, sd, &v2); 6 7 vec_add (& b1 ->move, &v1, &b1 ->move); // new speed of the balls 8 vec_add (& b2 ->move, &v2, &b2 ->move); 9 } 0 } S. Huber, K. Safdar, A. Schröcker: Pool Billiard, An OpenGL-based billiard simulation 32/34

Outline 1 Modelling the Balls 2 Modelling the Table 3 Force Simulation 4 Viewing 5 Animation 6 Control S. Huber, K. Safdar, A. Schröcker: Pool Billiard, An OpenGL-based billiard simulation 33/34

Control Left and right arrow keys: Rotate around the y-axis Up and down arrow keys: Move towards the ball and backwards (eye y does not change) The keys y and Y : Decrease and increase eye y Left mouse button: Push the ball S. Huber, K. Safdar, A. Schröcker: Pool Billiard, An OpenGL-based billiard simulation 34/34