Sunday 29 July 2012

Monster Truck Trials - IPhone / Ipad Game - Adobe Premier - Preview

So apparently it is a good idea to do some pre-launch media, well how do you do that?
One first step in the right direction would be to get a video trailer together.



I have created the following trailer for my new game "Monster Truck Trials" (Working title)

I used a program called reflection to record the in game scenes from my IPad.
I created some basic rendered graphics using blender.
Then using adobe premier I pinned it all together.

I'm not a music composer but it is important to make sure that any music you use is licensed, this is the same for any external media you use in your production.
I have found that http://luckylionstudios.com provide some great backing tracks!


Friday 27 July 2012

Mountain Lion - Quick Review.

How exciting a new release of the Mac OS.

After a 4 GB download which took me over a day on normal broadband speeds in west wales, the installation started, it lied to me a few times at first it stated there was 30 minutes to go, then eventually 4 minutes, then back up to 30 minutes, I'm not sure if I misread something but overall it defiantly took a good hour.

Now to restart my mac..... well it worked, otherwise I would no doubt of started this post with "Mountain Lion Wrecked My Mac" which it didn't it went nice and smoothly.

Things I like so far.


  • I can now get to the top of my mail quickly by clicking the sort bar
  • The notifications are handy
  • Safari, seems more responses, it used to hang a lot with the timer icon, this seems to of stopped.
  • Performance, its hard to tell it seem similar but I did get a lot of hanging before with lots of applications open, maybe this will improve.
Notifications in action...


Moans
  • It does feel like a service pack that I just had to pay £13.99 for not a new operating system.
  • I seem to have to re-install or update a lot of things, x-code has to be upgraded to the latest version, another 1.5GB download, also x11 needs re-installing.

Overall.

I think it was worth the upgrade and I'm sure I will find some new toys to play with.
Make sure you have plenty of time to download everything and make the installations.


Tuesday 24 July 2012

Bullet Physics - Cocos3d - Collisions using contact-added callback and masks

Within my current game I want my truck to be able to come into contact with a power up.
When this happens I don't want it to influence the truck, just register the impact.

There is quite a straight forward way of dealing with collisions using bullet and this is using the contact added callback.

You will need to create one method that handles what happens when a collision occurs and then set a bullet variable to be equal to this method.

Then all you will have to do is register each object that uses the callback for collisions.

Create a function with the following signature


bool contact_callback( btManifoldPoint &btmanifoldpoint,
                            const btCollisionObject *btcollisionobject0,
                            int part_0, int index_0,
                            const btCollisionObject *btcollisionobject1,
                            int part_1, int index_1 ) 


Within this method you will be returned a pair of objects that have collided, it is up to you what you do with them.

I use the

rigidBody->setUserPointer(physicsObject);

method of the rigidBody to set a pointer to my own object.

This allows me to cast the pointer from the collisions to my own objects.

CC3PhysicsObject3D *phyObject0 = ( CC3PhysicsObject3D * )( ( btRigidBody * )btcollisionobject0 )->getUserPointer();
    

Note even if you remove an object that comes into contact immediatly from your physics world it will still call this call back a few times, I have an isBeingRemoved property on my own object which I set as a further check.

Then all you have to do is register your callback with the world

 gContactAddedCallback = contact_callback;

I do this at the bottom of my world initialisation code.

Finally I register any rigid bodies that you want to call this callback method when a collision has occurred.


pObject.rigidBody->setCollisionFlags(pObject.rigidBody->getCollisionFlags() |  btRigidBody::CF_NO_CONTACT_RESPONSE |btCollisionObject::CF_CUSTOM_MATERIAL_CALLBACK );


Here pObject is my physics. I use two flags here

btRigidBody::CF_NO_CONTACT_RESPONSE 

Which register the rigid body as not having an affect on the physics world

and

btCollisionObject::CF_CUSTOM_MATERIAL_CALLBACK 

Which registers the object to call the gContactAddedCallback related call back function.

I hope the above is of some help!

Duncan.



   


Monday 23 July 2012

Custom motion states - btMotionState - Bullet Physics

Instead of having one main loop where the rendering of world objects are performed, it makes sense to use Bullets motion states.  Instead of updating the position of all your objects with each render loop, you can use bullet to only update objects that have moved!


What do you need to do?


Well you will need to create your own motion state.


Within Xcode create yourself a c++ header.


Rename it to .hpp 
This will allow you to have a mixture of c++ and Objective-C code.


When my class is only going to be small I have written my entire class within the header file, this is no doubt bad practice but for small classes I find it easier to manage.


Remember an Objective-C class cannot inherit a C++ class, but you can write a C++ class with Objective-C code.


So I create my class which inherits btMotionState.


class MyMotionState : public btMotionState {

Now within my class I have the code which updates my cocos3d node.

virtual void setWorldTransform(const btTransform &worldTrans) {
        if(NULL == mVisibleobj)
            return       
        
        btQuaternion rot = worldTrans.getRotation();
        mVisibleobj.quaternion = CC3Vector4Make(rot.getX(), rot.getY(), rot.getZ(), -rot.getW());
       
        btVector3 pos = worldTrans.getOrigin();
        mVisibleobj.location = CC3VectorMake(pos.getX(), pos.getY(), pos.getZ());;
     
    }


It's that simple.

On creation of an instance of this motion state make sure you can set a reference to your CC3Node.

 MyMotionState(const btTransform &initialpos, CC3Node *node) {
        mVisibleobj = node;
        mPos1 = initialpos;
    }

Now use your new motion state instead of the default one.

Duncan.



Wednesday 18 July 2012

Bullet to Cocos3d - btQuaternion to CC3Vector4

Oh, how I feel silly, I discovered that my quaternion definition is wrong.


The previous post is a bit of a waste now as all you need to set is the following



 btQuaternion btq = transform.getRotation();
 CC3Vector4 quaternion = CC3Vector4Make(btq.getX(), btq.getY(), btq.getZ(), -btq.getW());


Notice the 


-btq.getW()


One silly
Duncan.

Thursday 12 July 2012

Bullet physics btRaycastVehicle + Cocos3D

My long term goal is to make some form of truck game.  I'm not 100% sure what the game objectives will be, but I do know that it will be in 3D and will require simulated physics.


As a little example of what I have accomplished so far(very basic) I have recorded the following video.






Now that I have got Cocos3D up and running with Bullet physics, I thought the first step would be to try and implement some of their examples.


This is where the ray cast vehicle came into play.

I have had to make some alterations to the btRaycastVehicle library to get it up and running.


I could not for the live of me get the steering rotation to render correctly within cocos3d.


So I stripped out the steering rotation from within bullet and now do this within my cocos3d app.


In


void btRaycastVehicle::updateWheelTransform( int wheelIndex , bool interpolatedTransform)


I have changed


wheel.m_worldTransform.setBasis(steeringMat * rotatingMat * basis2);


to


wheel.m_worldTransform.setBasis(steeringMat   * btMatrix3x3(m_chassisBody->getOrientation()));


Now within my cocos3d application I have a wheel node that renders the position and steering angle of the physics wheel and a child node that is actually the tyre.


I rotate the tyre node manually from my wheels rotation information


tyre.rotation = cc3v(-1 * (wheelInf.m_rotation * (180/3.142)),0,0);

The above converts the m_rotation in radians to the degrees required for cocos3d rotation.

Unfortunatly after all this it has shown to me that a raycast vehicle doesn't really work for trucks moving over terrain, so I will now need to construct one from scratch! Lets see what happens....

Duncan.





Wednesday 11 July 2012

Create a Bullet Physics library for IOS, iPhone, IPad, Xcode

This is a rough run down, on how I get the Bullet Physics library working within my applications.


First of all I find out what is the latest stable build by going to


http://code.google.com/p/bullet/downloads/list


At current it is


Bullet 2.80 Physics SDK SP1 (svn r2531)  


Don't download this library we will get hold of it by SVN.


This gives me the current revision number


I then create  a directory where I would like to build the libraries.


from the terminal I go to my main build directory and create a new one for my bullet library


mkdir ./Bullet2.8-2531


I now use a build script written by Hoon Hwangbo


cd ./Bullet2.8


git clone git@github.com:Eonil/Bullet-PhysicsEngine-BuildScript-iOS.git


Now you need to update the build script to use the latest revision.


vi ./Bullet-PhysicsEngine-BuildScript-iOS/Script/BuildAll.sh


Find the line that reads


svn            checkout http://bullet.googlecode.com/svn/trunk/ -r 2440 ./Source


and replace 2440 ( the revision number when the script was written) with 2531 (the current revision number)


save your file and exit vi (or whatever program you are using)


Now compile your library


sh ./Bullet-PhysicsEngine-BuildScript-iOS/Script/BuildAll.sh ./Build


Now I create a new project in Xcode ( I generally use a cocos3d template)


Now click on your target and goto "Linked Frameworks and Libraries"
Click + then add other, navigate to your compiled libraries directories and add the libraries you require, as a guide go for

  • libBulletCollision.a
  • libBulletDynamics.a
  • libBulletMultiThreaded.a
  • libBulletSoftBody.a
  • libLinearMath.a
  • libMiniCL.a
This does seem to manually add your directory settings to your build configuration but I still add my main directory (probably not needed)


So I go to my target, click on build settings and locate "User Header Search Paths"
I then add the path to my Package directory. 


Now all I have to do within my code is import the header as follows



#import "btBulletCollisionCommon.h"

Finally rename your .m files that include the header to .mm to allow for the inclusion of external c++ code.


You should now be able to build your project.

I hope this was of some help.


**Note at current this only works on the device, I have managed to get this working not he simulator, but need to simplify it before adding the instructions.

Duncan.















Monday 9 July 2012

Bullet Physics, Cocos3d, Debug Drawer - setDebugDrawer

I have recently managed to get the Bullet Physics debug drawer working within cocos3d.

To implement this I have created a C++ class that has access to singleton class which in turn can draw on my 3d scene.

My class inherits btIDebugDraw

class debugDrawer : public btIDebugDraw

Within


debugDrawer::drawLine(const btVector3& from,const btVector3& to,const btVector3& color)
{
  
   RuleSet *rule = [General SharedGeneral].RuleSet;
   [rule debugLine:from.x() y:from.y() z:from.z() :to.x() dy:to.y() dz:to.z()];

}

Within my shared class I have my line drawing code

-(void) debugLine :(float)x y:(float)y z:(float) z:(float)dx dy:(float)dy dz:(float) dz {
    
    float arr_location[] = {x,y,z, dx,dy, dz };
    CC3LineNode* lineNode = [CC3LineNode nodeWithName: @"Line test"];
    [lineNode populateAsLineStripWith: 2
                             vertices: arr_location
                            andRetain: YES];
    lineNode.color = ccGREEN;
    
    [_lines addObject:lineNode];
    [_activeWorld addChild:lineNode];   
  //Thanks Bill :-)  
}

I referenced my shared object which allows me to draw lines in my 3d world.

When I initialise my 3d world I attach my debugDrawer

 debugDrawer *debug;
 debug = new  debugDrawer;
 dynamicsWorld->setDebugDrawer(debug);

At the end of every synchronisation of my physics world I call my debugDrawer

 _discreteDynamicsWorld->debugDrawWorld();  // This is the internal name of the class

Before calling each synchronisation on my physics world I call a debugStart session,
this removes all my previous lines from the scene, if you want pretty patterns don't bother with the following :-)

[general.RuleSet debugStart];

Within my shared class I have

-(void) debugStart {
   
    for (CC3LineNode* lineNode in _lines) {
        [_activeWorld removeChild:lineNode];
    }
    
    [_lines removeAllObjects];
    
}


Now I can see if my physics objects are being rendered correctly.
This only implements line drawing there are other methods within btIDebugDraw 
that you could implement for further functionality.



All the best.

Duncan.

Drawing a line in Cocos3D

I'm currently working on a debug drawer for Bullet Physics. 
To get this up and running I need to be able to draw some lines within cocos3d. 

I almost figured it out, but in the end Bill directed me in the right direction.

 float arr_location[] = {0.0,0.0,0.0, 5,5, 5 };
 CC3LineNode* lineNode = [CC3LineNode nodeWithName: @"Line test"];
 [lineNode populateAsLineStripWith: 2
                             vertices: arr_location
                            andRetain: YES];
 lineNode.color = ccGREEN;
    
 [self addChild:lineNode];

Populate arr_location with your way points for the line and add the node to your scene.

The plans I have for my debug drawer will be to record all lines added to the scene so I can remove them on the next debug draw and replace them with the new lines.