Havok - Can you change color of objects during runtime?

125 Views Asked by At

To anybody who has some experience with the Havok Physics Engine:

Is there a way to change the color of meshes/objects during runtime? I am working with the demo framework and I want to change the color of all the meshes/objects (in a demo) that are in-motion (velocity > 0). Its my first time using Havok. Can't find anything about it in the documentation I have.

Thanks!

On a sidenote: I have noticed that there are very little questions about Havok on stackoverflow and when I search questions about Havok online I can't seem to find anything. Where do all the Havok devs go to chat? They have a forum or something?

1

There are 1 best solutions below

1
On

The solution using HVD - Havok Visual Debugger:

// Needed for calling color change macro
#include <common\visualize\hkdebugdisplay.h>

// You'll of course need any other headers for any other physics stuff 
// you're doing in your file

void SetColorForPhysicsDebugger( unsigned int Red, unsigned int Green,
                                 unsigned int Blue, unsigned int Alpha, 
                                 const hkpCollidable* pCollidable )
{
    // Havok takes an unsigned int (32-bit), allowing 8-bits for 
    // each channel (alpha, red, green, and blue, in that
    // order).

    // Because we only need 8-bits from each of the 32-bit ints 
    // passed into this function, we'll mask the first 24-bits.
    Red &= 0x000000FF;
    Green &= 0x000000FF;
    Blue &= 0x000000FF;
    Alpha &= 0x000000FF;

    // Now we pack the four channels into a single int
    const uint32_t color = (Alpha << 24) | (Red << 16) | (Green << 8) | Blue;

    // We use the macro provided by Havok
    HK_SET_OBJECT_COLOR( reinterpret_cast<hkulong>( pCollidable ), color );
}

For more information about HVD: HVD and camera ,Setting mesh color