Quantcast

Jump to content

» «
Photo

camera/aim XYZ to angle

14 replies to this topic
HeresOtis
  • HeresOtis

    Mark Chump

  • Members
  • Joined: 29 Apr 2011

#1

Posted 11 July 2013 - 12:40 AM

How to get the Z angle of the camera's xyz or aiming xyz?
Or is it possible to get the Z angle of a searchlight?

Wesser
  • Wesser

    The complexity simplifier, the efficiency optimizer.

  • Members
  • Joined: 19 Aug 2006
  • European-Union

#2

Posted 11 July 2013 - 10:28 AM

As I understand, you would like getting the angle of lets say the point A pointing to the point B. Isn't the GET_ANGLE_BETWEEN_2D_VECTORS (05A4) command up to your requirements?

fireguy109
  • fireguy109

    It's a long way to the top

  • Leone Family Mafia
  • Joined: 30 Aug 2010
  • United-States

#3

Posted 11 July 2013 - 12:11 PM Edited by fireguy109, 11 July 2013 - 12:14 PM.

I believe his usage would be not of one object looking at another, as in getting the player's object angle relative to an external object, but instead getting it on its own without a basis for comparison, as in simply the angle of the camera at any given time. You'd have to identify the point at which the camera was pointing to use 05A4, wouldn't you?

E: this would work for static cameras like during some cutscenes I suppose, but it would be pretty difficult to do on the fly.

Silent
  • Silent

    Moderating Cookie Monster

  • Members
  • Joined: 01 Feb 2010
  • Poland

#4

Posted 11 July 2013 - 12:44 PM

Yeah. I guess finding an angle between camera position and its target point should be enough. Something as simple as

CODE
068E: get_camera_target_point_to 0@ 1@ 2@
068D: get_camera_position_to 3@ 4@ 5@

0063: 3@ -= 0@  // (float)
0063: 4@ -= 1@  // (float)

0604: get_Z_angle_for_point 3@ 4@ store_to 6@

Wesser
  • Wesser

    The complexity simplifier, the efficiency optimizer.

  • Members
  • Joined: 19 Aug 2006
  • European-Union

#5

Posted 11 July 2013 - 01:00 PM

Ofcourse, that command was meant to be combined with 068D and 068E. For some reason, it doesn't produce the same result, so I would advice to use Silent's method which have been pointed out so many times (with a quick search you would have avoided to formulate your question).

Silent
  • Silent

    Moderating Cookie Monster

  • Members
  • Joined: 01 Feb 2010
  • Poland

#6

Posted 11 July 2013 - 01:10 PM Edited by SilentPL, 11 July 2013 - 01:18 PM.

05A4 is extremely weird. Looks like the 2nd parameter is actually a normalised vector, also it's a... conditional*?

* If I'm wrong, excuse me - I haven't been looking into it now, but I remember that some vectors-related command was IF and SET.

EDIT:
Checked it now. 05A4 uses arcus cosinus:
http://www.wolframal...nput/?i=acos(x)

0604 uses arcus tangent with two arguments:
http://www.wolframal.../?i=atan2(1, x)

EDIT2:
No wonder they are returning different values:
http://www.wolframal...an2..., acos(x)

I'd stick to 0604 smile.gif

HeresOtis
  • HeresOtis

    Mark Chump

  • Members
  • Joined: 29 Apr 2011

#7

Posted 11 July 2013 - 01:38 PM

Thanks.

HeresOtis
  • HeresOtis

    Mark Chump

  • Members
  • Joined: 29 Apr 2011

#8

Posted 11 July 2013 - 02:06 PM

Can the same be done to get an X-angle & Y-angle?

Wesser
  • Wesser

    The complexity simplifier, the efficiency optimizer.

  • Members
  • Joined: 19 Aug 2006
  • European-Union

#9

Posted 11 July 2013 - 02:21 PM Edited by Wesser, 11 July 2013 - 10:53 PM.

Have a look here.

Actually, there is a simpler and faster way to retrieve the camera Z angle:
CODE
const
   INV_RAD_TO_DEG = -57.324841
end

0A8D: 1@ = read_memory 0x00B6F178 size 4 virtual_protect 0 // CCamera.m_fYawAngle
1@ *= INV_RAD_TO_DEG
0656: get_angle 1@ absolute_degrees_to 1@

HeresOtis
  • HeresOtis

    Mark Chump

  • Members
  • Joined: 29 Apr 2011

#10

Posted 11 July 2013 - 02:51 PM

Really appreciate it.

Wesser
  • Wesser

    The complexity simplifier, the efficiency optimizer.

  • Members
  • Joined: 19 Aug 2006
  • European-Union

#11

Posted 11 July 2013 - 03:34 PM Edited by Wesser, 11 July 2013 - 10:53 PM.

By the way, there are 2 other ways to get the camera pitch (X) angle:
  • Method 1 (m_fAimPitch gets set only when the player is aiming on 3rd person view):
    CODE
    const
       INV_RAD_TO_DEG = -57.324841
    end

    0A8D: 1@ = read_memory 0x00B7CDF0 size 4 virtual_protect 0 // CPlayer.m_clPlayerData.m_fAimPitch
    1@ *= INV_RAD_TO_DEG
    0656: get_angle 1@ absolute_degrees_to 1@

  • Method 2:
    • CLEO3 compatible:
      CODE
      const
         INV_RAD_TO_DEG = -57.324841
      end

      0A9F: 0@ = current_thread_pointer
      0@ += 0x10 // CScriptThread.m_iBaseAddress
      0A8D: 0@ = read_memory 0@ size 4 virtual_protect 0
      0@ -= @popFloat
      0AA8: call_function_method 0x0050AD40 struct 0x00B6F028 num_params 0 pop 0 fPitchAngle 1@ // CCamera__getPitchAngle
      0AA7: call_function 0@ num_params 0 pop 0 fValue 1@
      1@ *= INV_RAD_TO_DEG
      0656: get_angle 1@ absolute_degrees_to 1@

      // [...]

      :popFloat
      hex
         83EC 04   // sub     esp, 4
         D95C24 00 // fstp    [esp+4-4]
         8B4424 00 // mov     eax, [esp+4-4]
         83C4 04   // add     esp, 4
         C3        // retn
      end

    • CLEO4 only:
      CODE
      const
         INV_RAD_TO_DEG = -57.324841
      end

      0AA8: call_function_method 0x0050AD40 struct 0x00B6F028 num_params 0 pop 0 fPitchAngle 1@ // CCamera__getPitchAngle
      0AE9: pop_float 1@
      1@ *= INV_RAD_TO_DEG
      0656: get_angle 1@ absolute_degrees_to 1@

fireguy109
  • fireguy109

    It's a long way to the top

  • Leone Family Mafia
  • Joined: 30 Aug 2010
  • United-States

#12

Posted 11 July 2013 - 05:33 PM

QUOTE (Wesser @ Thursday, Jul 11 2013, 08:00)
Ofcourse, that command was meant to be combined with 068D and 068E.

Ah, my apologies. I'm not very could with SA coding, don't know all the opcodes.

Silent
  • Silent

    Moderating Cookie Monster

  • Members
  • Joined: 01 Feb 2010
  • Poland

#13

Posted 11 July 2013 - 07:13 PM Edited by SilentPL, 11 July 2013 - 07:40 PM.

QUOTE (Wesser @ Thursday, Jul 11 2013, 16:21)
Actually, there is a simpler and faster way to retrieve the camera Z angle:

Is is actually CCamera.CCam[0].Alpha? CCam has both Alpha and Beta, so I guess you could use them to get Y/Z (up/down and left/right) angle.

Wesser
  • Wesser

    The complexity simplifier, the efficiency optimizer.

  • Members
  • Joined: 19 Aug 2006
  • European-Union

#14

Posted 11 July 2013 - 10:15 PM Edited by Wesser, 11 July 2013 - 10:52 PM.

Nope, it doesn't concern CCamera's cams. I would prefer the "Alpha" value as stated by you, even though the amplitude of the angle is almost the same as the value given by that function except for their direction, but it isn't FOV dependent and thus a bit inappropriate (I don't know how much the FOV would compromise the correct result, if it does). Anyway, here is the code in case you are interested (I might screwed up the angle direction):
CODE
const
   RAD_TO_DEG = 57.324841
   INV_RAD_TO_DEG = -57.324841
end

0A8D: 0@ = read_memory 0x00B6F081 size 1 virtual_protect 0 // CCamera.m_cActiveCam
0@ *= 0x0238 // sizeof(CCam)
0@ += 0x00B6F19C // CCamera.m_astCams
0A8E: 1@ = 0@ + 0xAC // CCamera.m_fPitchAngle
0A8D: 1@ = read_memory 1@ size 4 virtual_protect 0
1@ *= INV_RAD_TO_DEG
0656: get_angle 1@ absolute_degrees_to 1@
0A8E: 2@ = 0@ + 0xBC // CCamera.m_fYawAngle
0A8D: 2@ = read_memory 2@ size 4 virtual_protect 0
2@ *= RAD_TO_DEG
2@ += 90.0
0656: get_angle 2@ absolute_degrees_to 2@

Wesser
  • Wesser

    The complexity simplifier, the efficiency optimizer.

  • Members
  • Joined: 19 Aug 2006
  • European-Union

#15

Posted 14 July 2013 - 11:54 AM Edited by Wesser, 14 July 2013 - 12:02 PM.

Bump and double post. 05A4 opcode computes the angle between two points around a third point and so between two 2D vectors. See the sample script below:
CODE
const
   POINT_A_X = 0.0
   POINT_A_Y = 1.0
   POINT_B_X = 0.0
   POINT_B_Y = -1.0
   POINT_C_X = 1.0
   POINT_C_Y = 0.0
end

var
   1@: Float
   2@: Float
   3@: Float
   4@: Float
   5@: Float
   6@: Float
end

1@ = POINT_A_X
2@ = POINT_A_Y
3@ = POINT_B_X
4@ = POINT_B_Y
5@ = POINT_C_X
6@ = POINT_C_Y
// Get vector A.
1@ -= 5@
2@ -= 6@
// Get vector B.
3@ -= 5@
4@ -= 6@
05A4: get_angle_between_vectors_origin_to 1@ 2@ and_origin_to 3@ 4@ store_to 7@

It will return 90 degrees.




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users