• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

[Solved] Difficulty adjusting camera angles through mouse position

Status
Not open for further replies.
I'm trying to get the camera to adjust through mousemovement.
When moving the mouse horizontally, the rotation should change. When moving it vertically, the angle of attack should change.

I've got it working nicely, but only when I enable them separately. Once I enable both, angle of attack changes jumps even when I move the mouse horizontally.

SetCurrentCamField() sets the value in a camerasetup. There's a timer trigger that applies that camerasetup every 0.03 seconds.

The code below is executed in a mousemovement trigger.
difX and difY are the difference between the previous mouse position and the current mouse position.

JASS:
                        set aoa = GetCameraField(CAMERA_FIELD_ANGLE_OF_ATTACK)
                        if aoa > 0 and aoa < R180 then
                            set difX = -difX
                            set difY = -difY
                        endif
             
                        set rot = GetCameraField(CAMERA_FIELD_ROTATION)
                        if rot == 0 then
                            set rotIncr = -difY // = Sin(0-rot)*(-difX) + Sin(-R90-rot)*(difY)
                            set aoaIncr = -difX // = Sin(-R270+rot)*(-difX) + Sin(-R180+rot)*(difY)
                        elseif rot < R90 then
                            set rotIncr = Sin(R90-rot)*(difX) + Sin(-rot)*(difY)
                            set aoaIncr = Sin(rot)*(difX) + Sin(R90+rot)*(difY)
                        elseif rot <= R180 then
                            set rotIncr = Sin(R180-rot)*(difX) + Sin(R90-rot)*(-difY)
                            set aoaIncr = Sin(-R90+rot)*(difX) + Sin(rot)*(-difY)
                        elseif rot < R270 then
                            set rotIncr = Sin(R270-rot)*(-difX) + Sin(R180-rot)*(-difY)
                            set aoaIncr = Sin(-R180+rot)*(-difX) + Sin(-R90+rot)*(-difY)
                        else // < R360
                            set rotIncr = Sin(R360-rot)*(-difX) + Sin(R270-rot)*(difY)
                            set aoaIncr = Sin(-R270+rot)*(-difX) + Sin(-R180+rot)*(difY)
                        endif
             
              
                        // These work when either one or the other is called. When I remove either, the other works nicely.
                        call SetCurrentCamField(CAM_ROT, Rad2Deg(rot) + rotIncr*LoadReal(htbCamFields, CAM_ROT, VALINCR), SLNT_ADJ, false)
                        call SetCurrentCamField(CAM_AOA, Rad2Deg(aoa) + aoaIncr*LoadReal(htbCamFields, CAM_AOA, VALINCR), SLNT_ADJ, false)

As usual, I was making it way more complicated than it needs to be. I rethought my entire approach and rewrote it:

JASS:
                        set rot = GetCameraField(CAMERA_FIELD_ROTATION)
                        set aoa = GetCameraField(CAMERA_FIELD_ANGLE_OF_ATTACK)
                        set rotIncr = Cos(rot-R90)*difX + Sin(rot-R90)*difY
                        set aoaIncr = Cos(rot+R90)*difY - Sin(rot+R90)*difX
                        set aoaIncr = Sin(-aoa)*aoaIncr

This works nicely.
 
Last edited:
Level 4
Joined
Feb 16, 2017
Messages
54
are you any chance to share this trigger, i am making a map and i need exactly this, but i can't do it with jass
 
Last edited:
Status
Not open for further replies.
Top