170 likes | 185 Views
This project review covers how to change speed, orient a car, and draw trees in a computer graphics program. It also includes code samples and tips on implementing these features.
E N D
CS559: Computer Graphics Lecture 23: Project 2 Review Li Zhang Spring 2008
Today • Project 2 review
Other basic features • How to change speed? • Add a slider with a callback to change timePerFrame • How to orient a car? • How to draw trees? • A triangle + a rectangle • A cone + a cylinder • Using gluQuadrics
Piecewise circles (x2,y2) (x1,y1) R2 R1 t in [0,1] theta1 = t*2*PI-PI; draw train at [ x1 + R1 * cos(theta1), y1 + R1 * sin(theta1) ] t in [1,2] theta2 = (t-1)*2*PI; draw train at [ x2 + R2 * cos(theta2), y2 + R2 * sin(theta2) ]
Arc-Length Parameterization (x2,y2) (x1,y1) R2 R1 t in [0,2*PI*R1] theta1 = t/(2*PI*R1)*2*PI-PI; draw train at [ x1 + R1 * cos(theta1), y1 + R1 * sin(theta1) ] t in [2*PI*R1, 2*PI*R1+2*PI*R2] theta2 = (t-2*PI*R1)/(2*PI*R2)*2*PI; draw train at [ x2 + R2 * cos(theta2), y2 + R2 * sin(theta2) ]
Piecewise Cubics P4 P3 P1 P2
Piecewise Cubics Task1: draw the whole curve DrawCubic(P4,P1,P2,P3); DrawCubic(P1,P2,P3,P4); DrawCubic(P2,P3,P4,P1); DrawCubic(P3,P4,P1,P2); For (t=0; t < 0.1; t+=0.01) { A=computePoint(Q1,Q2,Q3,Q4,t); B=computePoint(Q1,Q2,Q3,Q4,t+0.01); drawLine(A,B); } Fine with Hermite, Catmull-Ron, Cardinal How about Bezier? Task 2: find where the train is at time t: TrainLocation(P1,P2,P3,P4,t) If (0<=t<1) return computePoint(P4,P1,P2,P3,t) If (1<=t<2) return computePoint(P1,P2,P3,P4,t-1); If (2<=t<3) return computePoint(P2,P3,P4,P1,t-2); If (3<=t<4) return computePoint(P3,P4,P1,P2,t-3);
Arc-Length Parameterization • Arbitrary curves? P4 P3 P1 P2
Correct Orientation in 3D • Define and interpolate up vector
Implement simple physics • Energy conservation
Multiple Cars • Each has its own parameter t, assuming arc-length parameterization
Hack Shadow (XL,YL,ZL) (x,y,z)
Train smoke? • Balls moving upward and dissipating
Arc-length parameterization t s 0 1 L 0 Arc-length parameterization y x Freeform