Game and Graphics Programming for iOS and Android with OpenGL ES 2.0 by Marucchi-Foino Romain
Author:Marucchi-Foino, Romain [Marucchi-Foino, Romain]
Language: ru
Format: mobi, epub
Publisher: John Wiley & Sons
Published: 2012-01-02T20:00:00+00:00
FIRST-PERSON CAMERA WITH COLLISION DETECTION
In this section, you will discover how to add collision detection on your camera by re-implementing the first person camera code of the previous exercise. But this time, you will add a physics bound to the camera and, using the Bullet API, control the linear velocity of the collision shape to move around the scene.
To get started quickly, duplicate the template_chapter7-4 folder and rename it chapter7-4. The template already includes the same physics structure that you studied in the previous chapter, as well as the first-person camera control that you created in the previous section’s exercise.
You also have access to a .bullet file, which has already been linked to the project (located inside the SDK/data/chapter7-4) and has been exported from the Blender scene used for this tutorial. So before starting to code, study the untitled.blend file located in SDK/data/chapter7-4, because it is slightly different than the one you have been using so far in this chapter.
More precisely, focus on the physics properties that have been set for each object. Basically, the interior is using a static triangle mesh shape, and the cylinder object called “camera” uses a capsule shape. You do not have stairs in this scene, but if you did, a capsule shape would be a lot smoother to move around or climb stairs on compared to a cylinder that has a rough edge at its base.
The way to implement collision detection for your camera is to use the physics bound of an arbitrary collision shape (in this case, a capsule) and then use its position (which is maintained by Bullet) as the camera location. The collision object of the camera should be a dynamic object (no rolling physics) in order for it to always stay straight in space.
Follow the next steps to convert your existing first-person camera code into a fully functional, first-person camera that collides with the boundaries of your scene:
1. At the top of the templateApp.cpp, on the line after the move_delta variable declaration, add the following OBJMESH pointer variable to remember the camera collision object:
OBJMESH *camera = NULL;
2. Inside the templateAppInit function, on the line right after the call to load_physic_world, insert the following code to query and remember the camera mesh pointer, and then once queried, force the physical object to be dynamic and make it invisible for rendering (since you are strictly interested in the collision shape of the object and do not want to draw the mesh itself onscreen):
/* Query the camera mesh pointer. */
camera = OBJ_get_mesh( obj, "camera", 0 );
/* Set the rigid body to be a dynamic body. */
camera->btrigidbody->setAngularFactor( 0.0f );
/* Make the object invisible at render time. */
camera->visible = 0;
3. Move to the templateAppDraw function and, on the line before the end bracket of the if( move_delta.z ), insert the following code to be able to affect the linear velocity of the camera physical object based on the movement delta using the associated Bullet API:
/* Assign the linear velocity of the collision object and multiply
the delta by 6.
Download
Game and Graphics Programming for iOS and Android with OpenGL ES 2.0 by Marucchi-Foino Romain.epub
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
DirectX | Flash |
GIS | OpenGL |
Solid Works |
Deep Learning with Python by François Chollet(12526)
Hello! Python by Anthony Briggs(9871)
OCA Java SE 8 Programmer I Certification Guide by Mala Gupta(9761)
The Mikado Method by Ola Ellnestam Daniel Brolund(9752)
Dependency Injection in .NET by Mark Seemann(9297)
Algorithms of the Intelligent Web by Haralambos Marmanis;Dmitry Babenko(8262)
Test-Driven iOS Development with Swift 4 by Dominik Hauser(7745)
Grails in Action by Glen Smith Peter Ledbrook(7671)
The Well-Grounded Java Developer by Benjamin J. Evans Martijn Verburg(7521)
Becoming a Dynamics 365 Finance and Supply Chain Solution Architect by Brent Dawson(6759)
Microservices with Go by Alexander Shuiskov(6526)
Practical Design Patterns for Java Developers by Miroslav Wengner(6422)
Test Automation Engineering Handbook by Manikandan Sambamurthy(6401)
Secrets of the JavaScript Ninja by John Resig Bear Bibeault(6383)
Angular Projects - Third Edition by Aristeidis Bampakos(5785)
The Art of Crafting User Stories by The Art of Crafting User Stories(5313)
NetSuite for Consultants - Second Edition by Peter Ries(5254)
Demystifying Cryptography with OpenSSL 3.0 by Alexei Khlebnikov(5075)
Kotlin in Action by Dmitry Jemerov(5023)
