- Joined
- Nov 2, 2004
- Messages
- 1,985
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.
The code below is executed in a mousemovement trigger.
As usual, I was making it way more complicated than it needs to be. I rethought my entire approach and rewrote it:
This works nicely.
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: