Danh mục

3D Game Programming All in One- P8

Số trang: 30      Loại file: pdf      Dung lượng: 437.66 KB      Lượt xem: 15      Lượt tải: 0    
Thư Viện Số

Hỗ trợ phí lưu trữ khi tải xuống: 15,000 VND Tải xuống file đầy đủ (30 trang) 0

Báo xấu

Xem trước 3 trang đầu tiên của tài liệu này:

Thông tin tài liệu:

3D Game Programming All in One- P8: During the past several years while working on the Tubettiland “Online Campaign” softwareand more recently while working on the Tubettiworld game, I figure I’ve receivedmore than a hundred queries from people of all ages about how to get started makinggames. There were queries from 40-year-olds and 13-year-olds and every age in between.Most e-mails were from guys I would estimate to be in their late teens or early 20s.
Nội dung trích xuất từ tài liệu:
3D Game Programming All in One- P8 3D Programming 117 if (%scale < 5.0) // and hasnt gotten too big %scale += 0.3; // make it bigger else $grow = false; // if its too big, dont let it grow more } else // if its shrinking { if (%scale > 3.0) // and isnt too small %scale -= 0.3; // then make it smaller else $grow = true; // if its too small, dont let it grow smaller } %shape.setScale(%scale SPC %scale SPC %scale); %shape.setTransform(%lx SPC %ly SPC %lz SPC %rx SPC %ry SPC %rz SPC %rd); schedule(200,0,AnimShape, %shape, %dist, %angle, %scale);}function DoAnimTest()// ----------------------------------------------------// a function to tie together the instantiation// and the movement in one easy to type function// call.// ----------------------------------------------------{ %as = InsertTestShape(); $grow = true; AnimShape(%as,0.2, 1, 2);}This module is almost identical to the MoveShape() module we worked with earlier.The function AnimShape accepts a shape handle in %shape, a distance step as %dist, an anglevalue as %angle, and a scaling value as %scale and uses these to transform the shape indi-cated by the %shape handle.First, it obtains the current position of the shape using the %shape.getTransform() methodof the Item class.As with the earlier MoveShape() function, the AnimShape() function fetches the transform ofthe shape and updates one of the axis values.Then it updates the rotation value stored %rd. Team LRN118 Chapter 3 ■ 3D Programming Concepts Then it adjusts the scale value by determining if the shape is growing or shrinking. Depending on which way the size is changing, the scale is incremented, unless the scale exceeds the too large or too small limits. When a limit is exceeded, the change direction is reversed. Next, the scale of the shape is changed to the new values using the %shape.setScale() method for the shape. Finally, the function sets the items transform to be the new transform values within the %shape.setTransform() statement. The DoAnimTest() function first inserts the new instance of the shape object using the InsertTestShape() function and saves the handle to the new object in the variable %as. It then calls the AnimShape() function, specifying which shape to animate by passing in the handle to the shape as the first argument and also indicating the discrete movement step distance, the discrete rotation angle, and the discrete size change value with the second, third, and fourth arguments. To use the program, follow these steps: 1. Make sure youve saved the file as 3DGPAi1CH3animshape.cs. 2. Run the Chapter 3 demo using the shortcut in the 3DGPAi1 folder. 3. Press the Start button when the demo screen comes up. 4. Make sure you dont move your player-character after it spawns into the game world. 5. Bring up the console window. 6. Type in the following, and press Enter after the semicolon: exec(CH3/animshape.cs); You should get a response in the console window similar to this: Compiling CH3/animshape.cs... Loading compiled script CH3/animshape.cs. This means that the Torque Engine has compiled your program and then loaded it into memory. The datablock definition and the three functions are in memory, waiting to be used. 7. Now, type the following into the console, and close the console quickly afterward: DoAnimTest(); What you should see now is the heart dropping from the air to the ground; it then begins moving away from you toward the right. Go chase after it if you like, to get a sense of how fast it is moving. Team LRN 3D Programming 119Go ahead and experiment with the program. Try moving the item through several axes atonce, or try changing the distance.3D AudioEnvironmental sounds with a 3D component contribute greatly to the immersive aspectof a game by providing positional cues that mimic the way sounds happen in real life.We can control 3D audio in the scene in much the same way we do 3D visual objects.Type the following program and save it as 3DGPAi1CH3animaudio.cs.// ========================================================================// animaudio.cs//// This module contains the definition of an audio emitter, which uses// a synthetic water drop sound. It also contains functions for placing// the test emitter in th ...

Tài liệu được xem nhiều: