Home › Forums › General Questions › Align Euler Rotation to (Raycast) Vector
- This topic has 11 replies, 2 voices, and was last updated 1 year, 6 months ago by Thomas Fabini.
-
AuthorPosts
-
2023-04-26 at 8:26 pm #63302Thomas FabiniCustomer
Hi guys,
dunno if this has been solved or discussed before:
I would like to align an object to the normal returned by the raycaster.
I assume the returned values to be a directional vector, which I would need to translate to rotational euler values to align an object with the surface which the raycast hit.
Or by any means aligning an object to the surface which the raycast hit, that is.Can this be achieved with puzzles? Could you point me maybe to an example if this has been featured in any of the demos? If it’s possible to perform the conversion via javascript that would be great too…
Thanks,
Thomas2023-04-26 at 8:44 pm #63303kdvParticipantCan this be achieved with puzzles?
https://www.soft8soft.com/docs/manual/en/puzzles/Objects.html#set_object_direction
If it’s possible to perform the conversion via javascript that would be great too…
https://cdn.soft8soft.com/demo/examples/index.html#webgl_geometry_terrain_raycast
Puzzles and JS coding. Fast and expensive.
If you don’t see the meaning in something it primarily means that you just don’t see it but not the absence of the meaning at all.
2023-04-27 at 7:01 pm #63317Thomas FabiniCustomerHi kdv,
thank you very much for your quick answer, right on spot…
Set object direction – for unknown reasons I missed that one. It does exactly the conversion I’m looking for. But with some preliminary testing I assume the normal returned by the raycaster puzzle to be the vector of the object orientation – the aligned object orientates spherical toward the center of the object instead of aligning with its surface, it seems.I’ll try to go with your second suggestion and use the face normals from the api raycaster – besides that one seems to return more data – like the coordinates for a second uv set and pretty usefull stuff.
Anyways, thank you for pointing me in the right direction.
Thomas2023-04-27 at 7:10 pm #63318kdvParticipantthe aligned object orientates spherical toward the center of the object instead of aligning with its surface, it seems.
Try with and without the
point
option. And keep in mind that the default and initial direction is horizontal along Y axis,[0, -1, 0]
On my side it works as expected https://v3d.net/ctv
besides that one seems to return more data – like the coordinates for a second uv set and pretty usefull stuff.
Yeap, the original raycaster is much more interesting )))
Puzzles and JS coding. Fast and expensive.
If you don’t see the meaning in something it primarily means that you just don’t see it but not the absence of the meaning at all.
2023-04-28 at 9:43 pm #63330Thomas FabiniCustomerHi kdv,
with your recent post I realized some serious errors in my setup – first one that I was feeding the raycaster the right object for the origin of the raycast, but a direction vector in world coordinates [0,1,0] which does cast, but always in y+ without rotating with the object…
So there’s that. Your info regarding the default raycast direction proved useful because that’s what it did when i fed the object’s direction, casting in y-.
About the point option, I’ve had it off (expecting face normals, instead a single point in space) an on, too – but with the current setup it’s really hard to tell the difference.I will need to do some isolated testing next, take the raycaster features out of the current vr setup and check the basics in a simple test scene.
Thanks again for your hints!
2023-04-28 at 9:50 pm #63331kdvParticipantIs there a part which features the raycaster?
Enter one of the rooms and you will see the raycaster working…
Puzzles and JS coding. Fast and expensive.
If you don’t see the meaning in something it primarily means that you just don’t see it but not the absence of the meaning at all.
2023-04-29 at 8:34 am #63346Thomas FabiniCustomerI realized that right after sending the post, obviously… duh.
It works flawlessly and beautiful, definitely face normals – your solution is based on puzzles I assume?I’m trying to achieve similar features, only not raycasting from camera / mouse but cast from an object and based on it’s direction in 3D space, and besides maybe some modifications to the cursor based on the uv coordinates returned by the raycaster.
Anyways – your suggestions and findings lead to the conclusion it’s possible, even with puzzles.
2023-04-29 at 8:41 am #63347kdvParticipantyour solution is based on puzzles I assume?
Yes. Puzzles only in this case
As my move pointer is facing up by default (although it should be facing left) I need to rotate it by 90° after its direction has been set.
Puzzles and JS coding. Fast and expensive.
If you don’t see the meaning in something it primarily means that you just don’t see it but not the absence of the meaning at all.
2023-04-30 at 5:32 pm #63365Thomas FabiniCustomerThank you very much for posting your setup…
nice setting the rotation only after the normals change, and setting the additional rotation after setting the direction to the pointer… Is it neccesary converting prevNormal to string before checking it against the current normal? Would checking array against array go wrong?
The setup I use was less slick and efficient, but from the basics pretty similar.
Today I took that into a separate testing scene it actually worked, but it really helped checking the setup against your approach and understanding it further.
The Raycaster seems rock solid, as far as I can tell, it returns definitely face normals unless “point” is checked. https://v3d.net/j2dAttachments:
You must be logged in to view attached files.2023-04-30 at 5:43 pm #63367kdvParticipantIs it neccesary converting prevNormal to string before checking it against the current normal?
That’s one of workarounds in JS to compare two lists (arrays) . Otherwise the condition will never return
true
.Puzzles and JS coding. Fast and expensive.
If you don’t see the meaning in something it primarily means that you just don’t see it but not the absence of the meaning at all.
2023-04-30 at 7:21 pm #63369kdvParticipantit returns definitely face normals unless “point” is checked
In fact a raycaster always returns correct face normals. If the
point
option is not enabled they are “moved” to intersection points.
A unit vector from [0,0,0] and the same unit vector from [x,y,z] represent two points with different coordinates.Puzzles and JS coding. Fast and expensive.
If you don’t see the meaning in something it primarily means that you just don’t see it but not the absence of the meaning at all.
2023-05-04 at 8:09 pm #63511Thomas FabiniCustomerThat’s one of workarounds in JS to compare two lists (arrays) .
That’s something I wasn’t currently aware of – thanks for the explanation.
Today I got the whole raycaster setup finally working. At the end things got funny when the raycaster hits rotated objects, specifically dynamically rotated ones, or child objects of rotated parents.
What worked was adding the rotation of the raycast target object to the normal direction while setting and getting all rotations in world space. What helped, too was setting child objects to the -y (as the default raycast) world orientation before parenting.There is still an issue which might relate to Euler rotations and gimble lock, in my setup I can work around it. When it gets to math and vector math my brain goes like “just keep looking for a solution – I’m taking a break “.
-
AuthorPosts
- You must be logged in to reply to this topic.