Download presentation
Presentation is loading. Please wait.
Published byCharlotte Montgomery Modified over 8 years ago
1
Copyright © Roger Webster, Ph.D. Shooting 3D Objects Roger Webster, Ph.D. CS475 3D Game Development And Computer Animation
2
Copyright © 2010 Roger Webster, Ph.D. 2 Load weapon (gun.fbx) object(s) Put in front of camera Move gun.fbx object when fired (recoil) Or use transparent tga files Use mouse and game controller to shoot. Some options exist for target hits. Each target object must be a separate fbx file Make sure all fbx model files have embedded textures CS475 3D Game Development and Computer Animation Shooting Objects - preliminaries
3
Copyright © 2010 Roger Webster, Ph.D. 3 Shooting options-> determining target hits Bullet/Rocket traversal with collision detection Screen picking using Z-buffer (openGL) Ray casting with collision detection CS475 3D Game Development and Computer Animation
4
Copyright © 2010 Roger Webster, Ph.D. 4 Shooting options Bullet/Rocket traversal with collision detection
5
Copyright © 2010 Roger Webster, Ph.D. 5 Shooting options Bullet/Missile traversal with collision detection Load missile.fbx (load N of them) Fire missile (if you have one) Missile traverses forward each loop localpos.z = speed Update loop test collision detection missile vs all target objects If missile runs out of gas (distance) then it is reset If speed > size of target objects missile may not register hit Collision detection (accuracy vs speed)
6
Copyright © 2010 Roger Webster, Ph.D. 6 Collision Detection options Spherical collision detection Bounding Boxes Polygonal collision detection Hierarchical Collision Detection Shooting options
7
Copyright © 2010 Roger Webster, Ph.D. 7 OpenGL Screen picking using Z-buffer CS475 3D Game Development Used for mouse clicking and selection of 3D objects Can be modified for shooting targets Uses screen coordinates (x,y) and Z-buffer hardware (Nvidia) Can be very fast Assign glloadname(index) to each rendered object Given any x,y screen coordinate check Z-buffer and return glname index
8
Copyright © 2010 Roger Webster, Ph.D. 8 Screen picking using Z-buffer CS475 3D Game Development
9
Copyright © 2010 Roger Webster, Ph.D. 9 Screen picking using Z-buffer CS475 3D Game Development
10
Copyright © 2010 Roger Webster, Ph.D. 10 void myDisplay(void) {glMatrixMode(GL_MODELVIEW); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity(); muopengl_camera.Render(); glInitNames(); glPushName(0); glLoadName(100); Model1.Render(); glEnd(); glLoadName(101); Model2.Render(); glEnd(); glPopName(); draw_window_items(); glutSwapBuffers(); }
11
Copyright © 2010 Roger Webster, Ph.D. 11 Screen picking using Z-buffer CS475 3D Game Development void mouse(int button, int state, int x, int y) { // Respond to mouse button presses. foundobj = RetrieveObjectID(x, y); … } See Picking demo on web site
12
Copyright © 2010 Roger Webster, Ph.D. 12 Shooting options Ray casting with collision detection
13
Copyright © 2010 Roger Webster, Ph.D. 13 Shooting options Ray casting with collision detection public bool checkRayCollision (Vector3 rayOrigin, Vector3 rayDir, float length, out Vector3 collisionPosition) public bool checkRayCollision (Vector3 rayOrigin, Vector3 rayDir, float length, out Vector3 collisionPosition, out Vector3 surfaceNormal) public bool checkRayCollision (Vector3 rayOrigin, Vector3 rayDir, float length, bool closestCollision, out Vector3 collisionPosition, out Vector3 surfaceNormal) public bool checkCollision (CollidableModel collidableModel, out Vector3 collisionPosition, out Vector3 surfaceNormal) //NOTE MODEL TO MODEL COLLISION DETECTION RETURNS COL_POS AND SURFACE_NORMAL IN WORLD COORDINATE SYSTEM
14
Copyright © 2010 Roger Webster, Ph.D. 14 Shooting options Ray casting with collision detection
15
Copyright © 2010 Roger Webster, Ph.D. 15 Shooting options Ray casting with collision detection
16
Copyright © 2010 Roger Webster, Ph.D. 16 Shooting options Ray casting with collision detection if (world.checkRayCollision(gzMissile.Position, dir, LengthofRay*5.0f, out cp, out surfaceNormal)) { collision = true; resetMissile(); saveSn = surfaceNormal; saveCp = cp; endpos = cp + (surfaceNormal * 4.0f); lines.modifyLine(0, cp, endpos, Color.Red); drawthelines = true; target.Position = endpos; }
17
Copyright © 2010 Roger Webster, Ph.D. 17 Shooting options Ray casting with fast collision detection Useful to determine if an object is in the way For targets, must cast a ray and then check each target See demo on web site
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.