Tags

, , , , , , , , , , , , ,

Arkwood wore a dirty robe and a pair of old sandals. ‘Praise of the lentil and cast out the coin.’ He ain’t no Crates of Thebes.

‘What coin you have to seek sorrow for?’ I retorted, ‘But you are a hunchback, sure!’

Anyhow, I continued, Put this Oculus Rift virtual reality headset on and poke the bottle of mineral water.

Here’s the video of Arkwood poking the bottle:

But how does he prod the bottle? Well, first we need some collision detection code:

enum Collision { None, TV, Clock, Bottle, FrontWall, BackWall, LeftWall, RightWall };

We have defined a C++ enum, to represent all the objects in our virtual world that we can collide against.

Now, as per my 3D collision detection with C++ post, I can set the enum when my buddy collides with the bottle:

if ((Pos.x >= BottleMin.x && Pos.x <= BottleMax.x) &&
    (Pos.y >= BottleMin.y && Pos.y <= BottleMax.y) &&
    (Pos.z >= BottleMin.z && Pos.z <= BottleMax.z)) {
    currentCollision = Bottle;
    return PrevPos;
}

Perfect. On every render cycle of my Visual Studio app – using the Oculus SDK for Windows and OpenGL graphics library – I can check whether Arkwood is hitting the bottle:

bool bottleCollision = collisionClient->currentCollision == Bottle;
bool leftIndexPointing = inputState.Touches & ovrTouch_LIndexPointing;
bool rightIndexPointing = inputState.Touches & ovrTouch_RIndexPointing;

But we are also checking whether Arkwood is using the Oculus Touch controllers to point with his fingers. Why?

Because we will animate the bottle – making it squish – each time my sordid chum collides against it and pokes it with his finger:

if (bottleCollision && (leftIndexPointing || rightIndexPointing)) {
	bottleFrameCurrent = animationBottle->GetFrame(false);
}
else {
	bottleFrameCurrent = animationBottle->GetFrame(true);
}

Yep. If he collides against the bottle and one of his index fingers is prodding it then the bottle goes all squishy with animation. Otherwise the reset parameter of the GetFrame method is set to true so that no animation occurs. Detail of the animation can be found in my Blender animation in virtual reality post.

So what’s left? Well, we also vibrate the Touch controller for the finger he is poking with:

if (bottleCollision && leftIndexPointing) {
	ovr_SetControllerVibration(session, ovrControllerType_LTouch, 0.0f, 1.0f);
}
else {
	ovr_SetControllerVibration(session, ovrControllerType_LTouch, 0.0f, 0.0f);
}

Here we are sending vibrations to Arkwood’s left hand if he prods the bottle with his left index finger. We have similar code for his right hand. And if he prods with his left and right index fingers together then both Touch controllers vibrate.

So that’s it. Some C++ code to detect collision of our 3D bottle, plus squishy animation if Arkwood is also poking it with a finger.

Oh, and some vibration. Arkwood likes vibration. But I won’t allow him to put the vibrating Touch controllers in his underpants no more.

‘How dare you!’ Arkwood snapped, ‘I am a philosophical man. I seek no mortal pleasure.’

And off he went, to sleep in an old wine barrel just like Diogenes the Dog. But still the village he treated to exposed satisfaction. Which of us be Cynic?

Be. Gone.

Advertisements