CMSC 425 : Sring 208 Dave Mount and Roger Eastman Homework Due: Wed, Marh 28, :00m. Submit through ELMS as a df file. It an either be distilled from a tyeset doument or handwritten, sanned, and enhaned (using an a like CamSanner). Beware that sanned homeworks that are not learly legible may be returned to you, reuiring resanning and ossibly reoying. Avoid writing on both sides of the aer, sine the writing an bleed through to the other side. Late oliy: U to 6 hours late: 5% of the total; u to 24 hours late: 0%, and then 20% for eah additional 24 hours. Problem. Short answer uestions. Give two examles that might arise in a game imlemented in Unity, one where you want a rigid-body to have a ollider and one where you want a trigger. You have a triangle in the lane defined by three oints a, b, and (see Fig. ). You would like to interolate 5 eually-saed oints [0],..., [4] where [0] = a and [4] is the midoint between b and. For 0 i 4, give a formula that exresses [i] as an affine ombination of the oints a, b, and. (You may introdue additional temorary oints if you like, but exress them as affine ombinations of the original oints.) b a [4] [3] [2] [] [0] Figure : Problem : Affine ombinations. () In Unity, you want to rotate an objet through 90 degrees to our smoothly over a eriod of 4 seonds. In your Udate funtion, how many degrees of rotation should you aly? (Hint: Use the value of Time.deltaTime.) Problem 2. Your first assignment in your new job working for a game-engine omany is to design a funtion that determines whether a shere ollider and a asule ollider interset in 3-dimensional sae. We will walk through the stes to obtain the mathematial onditions behind this test and then derive a C# funtion to do it. The shere ollider has enter = ( x, y, z ) and radius r (see Fig. 2). It onsists of all the oints whose distane from is at most r. The asule ollider is given by three uantities: = ( x, y, z ) and = ( x, y, z ) are the endoints of the entral axis of the ollider and s is its radius. The ollider onsists of all the oints whose distane from the line segment
s r v l u t = t t () (d) Figure 2: Problem 2: Shere/Casule ollision. is at most s. Let us make the simlifying assumtions that,, and are all distint oints, and that does not line on the line assing through and. Define u to be the vetor direted from to (see Fig. 2), and define v to be the vetor direted from to. Note that these should not be normalized to unit length. For examle, u should eual the length of the segment. Using the oerations of affine and Eulidean geometry, exlain how to omute u and v from,, and. (Hint: If this seems easy, it is. We re just getting started.) Consider the infinite line l assing through and. Let t be the oint on l suh that the line segment t is erendiular to l (see Fig. 2() and (d)). (Note that t may generally lie outside the line segment, and this is fine for now.) Using the oerations affine geometry and Eulidean geometry, exlain how to omute the oint t. (Hint: The vetors u and v from art should ome in handy.) It is a fat (whih you do not need to rove) that if t lies within the line segment then it is the losest oint on this segment to. If not, the losest oint to is one of the endoints, or. () Exlain how to modify your solution to to determine the oint t on the line segment that is losest to. (Hint: Just exlain how to modify your solution to to ahieve this.) (d) Combining the results of the revious arts, resent a test (in mathematial notation) that determines whether the two olliders interset. (Note: The boundaries do not need to interset. If one ollider is omletely ontained within the other, they are still onsidered to interset.) (e) Present a C# funtion with the following signature that imlements your intersetion test: bool ShereCasuleCollide(Vetor3, float r, Vetor3, Vetor3, float s) You may make use of the basi math/geometry funtions that Unity rovides (e.g., Vetor3 methods or Mathf funtions), but you annot use more advaned funtions (e.g., 2
Unity s CasuleCollider lass methods). Exat syntati orretness is not essential, but your rogram should be lose to valid C# ode. Problem 3. Insired by Tiny Planet videos and similar games (see Fig. 3), you have deided to reate a game where a layer moves around the surfae of a shere. In order to imlement your idea, you will need to define a oordinate frame for the layer objet. u r f Figure 3: Problem 3: Tiny-lanet oordinate frame. () Let us assume that the shere is entered at a oint, and it has a radius of s units. The layer s frame will be entered at some oint that lies on the shere. In order to indiate the diretion in whih the layer is faing, a seond oint is given on the surfae of the shere (see Fig. 3). These two oints define a great irle on the shere. The layer is situated so that its vertial axis is aligned with the vetor from to, and its forward-looking vetor is direted tangent to the shere at oint along the smaller ar of the great irle ontaining and (see Fig. 3()). (Let us make the simlifying assumtion that and are not olar oosites from eah other, for otherwise there are infinitely many great irles through and.) The objetive of this roblem is to define an orthonormal oordinate frame for the layer objet. The origin of this frame is. The basis vetors are: u: u relative to the layer (along the ray from through ) f: forward relative to the layer (tangent to the great irle through and ) r: right relative to the layer (erendiular to both u and f) Exlain how to omute the above three basis vetors using the oerations of affine and Eulidean geometry. Be sure that the final vetors are normalized to unit length. Hint: Trigonometry and alulus are not needed to solve this roblem. This an all be done using the standard basi of Eulidean geometry (suh as affine ombinations, dot rodut, and ross rodut). It is easiest to omute these in the order u, then r, then f. 3
Present a C# funtion with the following signature that imlements your onstrution: void PlayerFrame(Vetor3, float s, Vetor3, Vetor3, out Vetor3 u, out Vetor3 f, out Vetor3 r) You may make use of the whatever standard math/geometry funtions that Unity rovides. Note: In your answers to arts and, state exliitly whether you are assuming a right-handed or left-handed world oordinate system. Standard math textbooks assume a right-handed system, meaning that ositive rotations are ounterlokwise and the rossrodut follows the right-hand rule. However, Unity uses a left-handed system, and this imlies that ositive rotations are lokwise and the ross-rodut follows the left-hand rule. For examle, see htts://dos.unity3d.om/sritreferene/vetor3.cross.html. Problem 4. Consider the series of shaes S 0, S,... shown in Fig. 4 below. With eah ste, eah line segment of length x is relaed by four segments eah of length x 2/4. Let S = lim i S i. S 0 S S 2 S 3... (0, 0) 2/4 Figure 4: Problem 4: Fratals and L-systems. Derive the fratal dimension of the boundary of S. You may exress your answer as the ratio of two logarithms. Derive an L-system to generate this shae. (For the sake of onsisteny, we reommend that you start in the lower-left orner of the unit suare and roeed ounterlokwise around the boundary.) In artiular, answer the following: (i) What are the values of the ste-size d and angle inrement δ? These values may hange from one shae to the next. If so, let d i and δ i denote the ste size and angle inrement for generating S i. Assume that the side length of S 0 is. (ii) What are the variables (symbols) V of your L-system? (iii) What is the start symbol (or start string), ω, for your system? (iv) What are the rodution rules, P? (Hint: Be sure that at the end of eah seuene, your urrent state is roerly oriented to start the next seuene.) (For guidane on solving this, see Marh 0 udate of Leture on fratals and L-systems. Problem 5. For your new game, you will be animating a model of a tower rane in 2-dimensional sae. The rane s arts are illustrated in Fig. 5. The struture sits on a base, whih we take to be the origin of the rane s oordinate system. 4
The vertial mast rises uwards H units to a oint where the oerator s booth sits. From here there is a horizontal jib uon whih slides a trolley at a distane of W units from the oerator. The hook is susended D units beneath the trolley. (Inreasing the value of D auses the hook to dro lower.) The referene (or bind) ose is suh that H 0 = 30, W 0 = 00, and D 0 = 70. There are four oordinate frames as shown in Fig. 5: the base, the oerator, () the trolley, and (d) the hook. W 0 = 00 00 oerator jib trolley b H 0 = 30 mast base hook D 0 = 70 a 20 d 40 Figure 5: Problem 5: Animating a tower rane. Following the naming onvention for the loal ose transformations (given in Leture 9) exress the following loal ose transformations a 3 3 homogeneous matries. (i) T [ d], whih translates oordinates in the hook frame to the trolley frame. (ii) T [b ], whih translates oordinates in the trolley frame to the oerator frame. (iii) T [a b], whih translates oordinates in the oerator frame to the base frame. (Hint: It may hel to reall the form of a translation matrix from Leture 6.) For examle, a oint loated 20 units below the hook would be reresented in the hook frame as [d] = (0, 20, ). Its oordinates with reset to the trolley would be [] = (0, 90, ). Thus, the transformation T [ d] should satisfy T [ d] 0 20 = 0 90 Show that by multilying these matries, we obtain a matrix T [a d] that mas oint into its oordinates with reset to the base frame. Verify your resulting matrix by showing that 00 T [a d] [d] = [a] = 40.. 5