Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to determine top side of cube #1622

Closed
hakanai-zz opened this issue Apr 2, 2012 · 2 comments
Closed

How to determine top side of cube #1622

hakanai-zz opened this issue Apr 2, 2012 · 2 comments
Labels

Comments

@hakanai-zz
Copy link

Hey,

first, thanks for helping me with #1603. I got jigLibs running und started to play around.

As I'm trying to get a dice rolling and read it's value, which is meant to be the top side, I found #1606 and thought, that I'd might be helpful in my case. So I got the dice rolling and it worked out well. The next step is to evaluate the value.
My camera is placed above the dice high on the Y-Axis and rotated on the X-Axis for a top-down view.

Now I'd thought, that I'll create a ray with the origin in the dice.position and going straight forwards the camera. The vector for this direction would be achieved as told in #1606, by extracting the rotation from the dice's matrix.

But I don't know yet how to continue. I tried assigning the dice's faces to a variable so I could loop them somehow to see which face was "hit" by the ray. But it returns a "undefined" when checking the value of the "dice.faces".
Am I on the wrong path? Isn't it possible to let the ray hit the dice and somehow check every face if it was hit, so I could determine the face and it's value attached to it?

Also I'd be very handy if someone of you would have worked with jiglib and the rigidBody method "addBodyForce", for it requires two vector as input, but using Three.Vector3 doesn't seem to work for me.

I set up a jsfiddle of my actual situation. The dice is rolling and I commented out my thoughts on the "addBodyForce" method.
The "ray thing" hasn't been implemented yet, because I wasn't sure if it was the right attempt.

JSFiddle: http://jsfiddle.net/XLGbm/

Thanks for reading the issue.

EDIT:
So "meanwhile" I learned, that the object returned by the intersect method of Ray.js contains the face or face id of the intersected object. That'd mean I could simply compare the IDs of the dice with the ID of the intersected object, right?

@mrdoob
Copy link
Owner

mrdoob commented Apr 3, 2012

Yep. I would get the dice position and throw a ray from, say position.y = 100 to the dice.position. The closes face intersected is the top face.

@hakanai-zz
Copy link
Author

Thanks for the assurance. I identified the values by comparing the materialIndex of the top face with the order of assigned textures. Thank you for your help

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants