We use cookies to ensure that we give you the best experience on our website. If you continue to use this site we will assume that you are happy with it.

Align Euler Rotation to (Raycast) Vector

Home Forums General Questions Align Euler Rotation to (Raycast) Vector

Viewing 12 posts - 1 through 12 (of 12 total)
  • Author
    Posts
  • #63302
    Thomas Fabini
    Customer

    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,
    Thomas

    #63303
    kdv
    Participant

    Can 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. 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 meaning at all.

    #63317
    Thomas Fabini
    Customer

    Hi 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.
    Thomas

    #63318
    kdv
    Participant

    the 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. 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 meaning at all.

    #63330
    Thomas Fabini
    Customer

    Hi 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!

    #63331
    kdv
    Participant

    Is there a part which features the raycaster?

    Enter one of the rooms and you will see the raycaster working…

    Puzzles and JS. 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 meaning at all.

    #63346
    Thomas Fabini
    Customer

    I 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.

    #63347
    kdv
    Participant

    your 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. 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 meaning at all.

    #63365
    Thomas Fabini
    Customer

    Thank 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/j2d

    Attachments:
    You must be logged in to view attached files.
    #63367
    kdv
    Participant

    Is 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. 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 meaning at all.

    #63369
    kdv
    Participant

    it 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. 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 meaning at all.

    #63511
    Thomas Fabini
    Customer

    That’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 “.

Viewing 12 posts - 1 through 12 (of 12 total)
  • You must be logged in to reply to this topic.