Jump to content

Normal to Rotation Help


practicing01

Recommended Posts

Hello, I'm trying to orient an object based on a raycast result transformation. The following isn't working. Any help would be appreciated.

 

  %rayResult = %obj.doRaycast(10000.0, %rayMask);

  %objTarget = firstWord(%rayResult);
  %objPos = getWords(%rayResult, 1, 3);
  %objDir = getWords(%rayResult, 4, 6);
  %transform = MatrixCreateFromEuler(%objDir);

  %box_.setTransform(%transform);
  %box_.position = %objPos;

Link to comment
Share on other sites

I can't find the function "doRaycast" in my build so I'm going to assume you're using the one defined in

https://www.garagegames.com/community/forums/viewthread/118723

(You may want to check the console for "Unknown command doRaycast" error if you're not using that).


Your code seems correct.

I would try

  %rayResult = %obj.doRaycast(10000.0, %rayMask);

  %objTarget = firstWord(%rayResult);
  %objPos = getWords(%rayResult, 1, 3);
  %objDir = getWords(%rayResult, 4, 6);
  %transform = MatrixCreate(%objPos,%objDir);

  %box_.setTransform(%transform);

But that's basicalliy the same.


For testing you may want to also add to that


echo("Ray result=" SPC %rayResult);


To be sure the raycast was correct.

Link to comment
Share on other sites

Alright, the code should work as this:

 

  %rayResult = %obj.doRaycast(10000.0, %rayMask);

  %objTarget = firstWord(%rayResult);
  %objPos = getWords(%rayResult, 1, 3);
  %objDir = getWords(%rayResult, 4, 6);

  %mat_rotx = MatrixCreateFromEuler( mAtan( mSqrt( %objDir.x*%objDir.x + %objDir.y*%objDir.y), %objDir.z) SPC "0 0");
  //%mat_localzrot = MatrixCreateFromEuler("0 0" SPC %localzrot);
  //%mat_rotx = MatrixMultiply(%mat_rotx,%mat_localzrot);
  %mat_rotz = MatrixCreateFromEuler("0 0" SPC mAtan(%objDir.x,%objDir.y));
  %transform = MatrixMultiply(%mat_rotz,%mat_rotx);

  %box_.setTransform(%transform);
  %box_.position = %objPos;

 

If you want to rotate the %box_ in the local z axis then remove the commenting and define %localzrot as the radian angle to rotate.

Link to comment
Share on other sites

Thanks irei1as! It worked. The code will probably help others in the future as well. This expert-level math is beyond lots of people. Game development requires engineer-level knowledge in a lot of aspects but if this engine wants to be newbie-friendly, rotations (other areas as well) need more helper functions.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...