|
0 registered members (),
1,738
guests, and 2
spiders. |
|
Key:
Admin,
Global Mod,
Mod
|
|
|
Re: Good and real example of 3d dice model
[Re: 3run]
#460531
07/03/16 08:03
07/03/16 08:03
|
Joined: Jun 2007
Posts: 1,337 Hiporope and its pain
txesmi
Serious User
|
Serious User
Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
|
Hi, I feel obliged to warn you that your dice is built wrong. Dices opposite sides always sum 7, so 1 is in front of 6, 2 of 5 and 3 of 4. The good new is that you only have to switch 2 and 6 for getting a correct dice. Dices up value can be computed by converting a world space up vector to dices coordinates because the resulting vector will always concur with the direction and sense of one of the cartesian axes of the dice (when the table plane is horizontal!), so only one single member of the resulting vector will hold a non zero value while the other two are equal to zero. Consider aligning the three upper values of the dice (4, 5 & 6) with positive cartesian axes, so the sign of the non zero value can be used to know witch side of the two is aligned with the computed vector. Take a look to dices opposite values and you will realize the average of every pair is always 3.5, so adding each axes half range multiplied by the computed vector plus 3.5 will give you upwards value. Here is the magic:
VECTOR vUp;
vec_set ( &vUp, vector(0, 0, 1) ); // world space up vector
vec_add ( &vUp, &ent->x ); // align to dices origin
vec_to_ent ( &vUp, ent ); // convert to dices coord system
BONE_RESULT = 3.5; // average on every axe
BONE_RESULT += sign(vUp.x) * 0.5; // 3&4 axis
BONE_RESULT += sign(vUp.y) * 1.5; // 2&5 axis
BONE_RESULT += sign(vUp.z) * 2.5; // 1&6 axis
DICE_RESULT += BONE_RESULT;
Try to understand and enjoy it!
|
|
|
Re: Good and real example of 3d dice model
[Re: txesmi]
#460534
07/03/16 10:11
07/03/16 10:11
|
Joined: May 2009
Posts: 5,377 Caucasus
3run
Senior Expert
|
Senior Expert
Joined: May 2009
Posts: 5,377
Caucasus
|
Hi, I feel obliged to warn you that your dice is built wrong. Dices opposite sides always sum 7, so 1 is in front of 6, 2 of 5 and 3 of 4. The good new is that you only have to switch 2 and 6 for getting a correct dice. Thank you man, I didn't have dice bones to take a look at so I searched the web, but made that model wrong anyway  Dices up value can be computed by converting a world space up vector to dices coordinates because the resulting vector will always concur with the direction and sense of one of the cartesian axes of the dice (when the table plane is horizontal!), so only one single member of the resulting vector will hold a non zero value while the other two are equal to zero. Consider aligning the three upper values of the dice (4, 5 & 6) with positive cartesian axes, so the sign of the non zero value can be used to know witch side of the two is aligned with the computed vector. Take a look to dices opposite values and you will realize the average of every pair is always 3.5, so adding each axes half range multiplied by the computed vector plus 3.5 will give you upwards value. Here is the magic:
VECTOR vUp;
vec_set ( &vUp, vector(0, 0, 1) ); // world space up vector
vec_add ( &vUp, &ent->x ); // align to dices origin
vec_to_ent ( &vUp, ent ); // convert to dices coord system
BONE_RESULT = 3.5; // average on every axe
BONE_RESULT += sign(vUp.x) * 0.5; // 3&4 axis
BONE_RESULT += sign(vUp.y) * 1.5; // 2&5 axis
BONE_RESULT += sign(vUp.z) * 2.5; // 1&6 axis
DICE_RESULT += BONE_RESULT;
Try to understand and enjoy it! This is indeed more elegant way to handle this! Thank you  I'll try to dive into this code, cause it's a bit over my head (my math sucks). Best regards!
|
|
|
Re: Good and real example of 3d dice model
[Re: 3run]
#460535
07/03/16 10:49
07/03/16 10:49
|
Joined: Jul 2001
Posts: 4,801 netherlands
Realspawn
OP

Expert
|
OP

Expert
Joined: Jul 2001
Posts: 4,801
netherlands
|
I am using a dice with symbols so i had only to change the number outcomes  also i mad one dice roll and all till now works figuring out the ground/plane thing in my own level as it does not bounce yet  so far so good Fixed it all works now need to study outcome and to put it in an other variable than the example
Last edited by Realspawn; 07/03/16 10:55.
|
|
|
Re: Good and real example of 3d dice model
[Re: txesmi]
#460538
07/03/16 12:08
07/03/16 12:08
|
Joined: May 2009
Posts: 5,377 Caucasus
3run
Senior Expert
|
Senior Expert
Joined: May 2009
Posts: 5,377
Caucasus
|
This is stange  I've done probably something wrong... Going to update the link on my webpage with this demo. Thank you man. Best regards!
|
|
|
Re: Good and real example of 3d dice model
[Re: Realspawn]
#460540
07/03/16 13:40
07/03/16 13:40
|
Malice
Unregistered
|
Malice
Unregistered
|
@txesmi
Very nice solution. It's like finding a constant z=1 normal regardless of the entity position. Like a sun casting light from directly above, you could modify this to determine which side of a die is most influenced by the imagined sun and which side would be fully shadowed.
That's very awesome! I wish I could think more like this and less raw mechanically.
|
|
|
|