Hello,
I'm trying to work my way around the bullet library by making a sample application (bouncing dice). I've got them rendering and moving correctly (they look quite good) - however I'm a bit stuck on determining which face of the dice is facing up? (relative to the floor). Is there an easy way of querying the bullet 3d model to get this information?
Any pointers would be great,
Thanks in advance,
James
Determining which face is "looking up"
-
- Posts: 508
- Joined: Fri May 30, 2008 2:51 am
- Location: Ossining, New York
Re: Determining which face is "looking up"
0x92c6008
0x92c6088
0x92c6108
0x92c6188
haha i'm so funny
What you can do though is push +Z (or whatever is 'up' in world space) through the inverse of the world transform of the die in question, to yield a vector in 'die space', which is something which you can then dot with all 6 possible face directions, picking the highest one.
0x92c6088
0x92c6108
0x92c6188
haha i'm so funny
What you can do though is push +Z (or whatever is 'up' in world space) through the inverse of the world transform of the die in question, to yield a vector in 'die space', which is something which you can then dot with all 6 possible face directions, picking the highest one.
-
- Posts: 456
- Joined: Tue Dec 25, 2007 1:06 pm
Re: Determining which face is "looking up"
Yep, I would do something similiar like this (never tested, so some adjustment should be done):
Ok now we have maxIndex that is an unique number in the range [0,5] that should represent the result (if mapped correctly).
Code: Select all
btScalar maxValue = 0;
int maxIndex = -1;
for (int i = 0;i<6;i++) {
const int side = i >= 3 ? i-3 : i;
const bool negative = i>=3;
btScalar value = dice->getWorldTransform().getBasis().getColumn(side).dot(btVector3(0.,negative ? -1. : 1.,0.));//Actually I should negate the first term...
if (value>maxValue) {
maxValue = value;
maxIndex = i;
}
}
-
- Posts: 5
- Joined: Mon May 18, 2009 9:20 pm
Re: Determining which face is "looking up"
Thanks Sparkprime & Flix,
I think I follow what is going on, I'll give it a go and see how I get on.
Just to add a bit more complexity I'm using jBullet and doing it on an Android device, but I'm sure it'll all work.
Thanks again,
James
I think I follow what is going on, I'll give it a go and see how I get on.
Just to add a bit more complexity I'm using jBullet and doing it on an Android device, but I'm sure it'll all work.
Thanks again,
James
-
- Posts: 5
- Joined: Mon May 18, 2009 9:20 pm
Re: Determining which face is "looking up"
Hello Sparkprime & Flix,
Just to let you know this worked like a charm, I would have posted sooner but I forgot.
Thanks again,
James
Just to let you know this worked like a charm, I would have posted sooner but I forgot.
Thanks again,
James