uberfoop
~=Admiral Stukov=~
- Reaction score
- 177
Coordinate Cameras
Version History:
7/21/09: Basic system posted
7/22/09: Updated with Toadcop's method for bypassing default terrain mapping
9/16/09: Updated to have better documentation and format
9/17/09: Updated to be more efficient
Requires:
-vJass
Code:
[ljass]//===================================================[/ljass]
This is a group of functions which each can be used to set the position and rotation of the Warcraft 3 camera.
In Warcraft 3, the closest distance to camera target useable is 100, and thus you're always moving a camera around some point a notable distance away. This bypasses that by using some vector math to place the camera target in a location such that, with desired camera rotation applied, the camera viewing point is at a specific desired coordinate.
Note that with this system, 'z' denotes absolute z, not z offset from terrain. Additionally, these functions are instant and affect all players.
Functions:
x, y, and z are the coordinates that the camera viewer will be at. a is the azimuth, the horizontal angle that the camera will face. v is the vertical angle; for this function, it is relative to the x/y plane (ie, a value of 30 will tilt the camera 30 degrees up from the wc3 plane). Roll is the camera roll.
Exactly the same as the last one except that rather than having v be the angle offset from the x/y plane, it's the angle offset from the vertical (ie, a value of 30 will be 30 degrees lower than straight up and 60 degrees up from the wc3 plane).
The x,y,z and roll inputs work exactly like the other two. However, instead of inputting two angles, for this function you input a target coordinate (fx,fy,fz) that you want the camera to face.
Example:
This will cause the camera to be 400 above the center of the map, facing eastward and diagonally down at the ground, with a roll of 0.
Example 2:
If you put this in your map and player one says "-", the callback goes off.
The commented things in the callback will cause simple looping parametric movement around the map origin if uncommented.
Version History:
7/21/09: Basic system posted
7/22/09: Updated with Toadcop's method for bypassing default terrain mapping
9/16/09: Updated to have better documentation and format
9/17/09: Updated to be more efficient
Requires:
-vJass
Code:
JASS:
// Coordinate Cameras
// By uberfoop
//
//
// ->What is this?
// It is a snippet with functions designed to allow the positioning
// of the wc3 camera based on spatial coordinates instead of target
// positions, distance to target, and what have you.
// Functions use absolute z value.
// They are instant and apply to all players.
//
// ->Functions:
//
// function SetCameraCoord takes real x, real y, real z,...
// ...real azimuth, real vertical, real roll returns nothing
//
// x, y, and z are spatial coordinates of the camera.
// azimuth is the horizontal rotation of the camera.
// vertical is the vertical angle of the camera. For example,
// '30' is 30 degrees up from paralell with the ground.
// roll is the roll angle of the camera.
//
//
// function SetCameraCoordB takes real x, real y, real z,...
// ...real azimuth, real vertical, real roll returns nothing
//
// This is the same as SetCameraCoord for everything except vertical.
// For vertical, this uses the angle down from the zenith. For example,
// '30' is 60 degrees up from paralell with the ground.
//
//
// function SetCameraCoordTarget takes real x, real y, real z,...
// ...real fx, real fy, real fz, real roll returns nothing
//
// x, y, and z are spatial coordinates of the camera.
// fx, fy, and fz are spatial coordinates that the camera will face.
// roll is the roll angle of the camera.
library CoordCameras
private function SetZ takes real z returns nothing
set z = GetCameraField(CAMERA_FIELD_ZOFFSET)+z-GetCameraTargetPositionZ()
call SetCameraField(CAMERA_FIELD_ZOFFSET,z,-.01)
call SetCameraField(CAMERA_FIELD_ZOFFSET,z,.01)
endfunction
globals
private real ccdist
private real radazim
private real radvert
endglobals
function SetCameraCoord takes real x, real y, real z, real azimuth, real vertical, real roll returns nothing
set radazim = bj_DEGTORAD*azimuth
set radvert = bj_DEGTORAD*vertical
set ccdist = 100*Cos(radvert)
call SetZ(z + 100*Sin(radvert))
call SetCameraPosition(x + ccdist*Cos(radazim),y + ccdist*Sin(radazim))
call SetCameraField(CAMERA_FIELD_TARGET_DISTANCE,100,0)
call SetCameraField(CAMERA_FIELD_ANGLE_OF_ATTACK,vertical,0)
call SetCameraField(CAMERA_FIELD_ROTATION,azimuth,0)
call SetCameraField(CAMERA_FIELD_ROLL,roll,0)
endfunction
function SetCameraCoordB takes real x, real y, real z, real azimuth, real vertical, real roll returns nothing
set radazim = bj_DEGTORAD*azimuth
set radvert = bj_DEGTORAD*vertical
set ccdist = 100*Sin(radvert)
call SetZ(z + 100*Cos(radvert))
call SetCameraPosition(x + ccdist*Cos(radazim),y + ccdist*Sin(radazim))
call SetCameraField(CAMERA_FIELD_TARGET_DISTANCE,100,0)
call SetCameraField(CAMERA_FIELD_ANGLE_OF_ATTACK,90 - vertical,0)
call SetCameraField(CAMERA_FIELD_ROTATION,azimuth,0)
call SetCameraField(CAMERA_FIELD_ROLL,roll,0)
endfunction
globals
private real azim
private real vert
endglobals
function SetCameraCoordTarget takes real x, real y, real z, real fx, real fy, real fz, real roll returns nothing
set fx = fx - x
set fy = fy - y
set radazim = Atan2(fy,fx)
set radvert = Atan2(fz - z,SquareRoot(fx*fx + fy*fy))
set ccdist = 100*Cos(radvert)
call SetZ(z + 100*Sin(radvert))
call SetCameraPosition(x + ccdist*Cos(radazim),y + ccdist*Sin(radazim))
call SetCameraField(CAMERA_FIELD_TARGET_DISTANCE,100,0)
call SetCameraField(CAMERA_FIELD_ANGLE_OF_ATTACK,bj_RADTODEG*radvert,0)
call SetCameraField(CAMERA_FIELD_ROTATION,bj_RADTODEG*radazim,0)
call SetCameraField(CAMERA_FIELD_ROLL,roll,0)
endfunction
endlibrary
[ljass]//===================================================[/ljass]
This is a group of functions which each can be used to set the position and rotation of the Warcraft 3 camera.
In Warcraft 3, the closest distance to camera target useable is 100, and thus you're always moving a camera around some point a notable distance away. This bypasses that by using some vector math to place the camera target in a location such that, with desired camera rotation applied, the camera viewing point is at a specific desired coordinate.
Note that with this system, 'z' denotes absolute z, not z offset from terrain. Additionally, these functions are instant and affect all players.
Functions:
JASS:
x, y, and z are the coordinates that the camera viewer will be at. a is the azimuth, the horizontal angle that the camera will face. v is the vertical angle; for this function, it is relative to the x/y plane (ie, a value of 30 will tilt the camera 30 degrees up from the wc3 plane). Roll is the camera roll.
JASS:
Exactly the same as the last one except that rather than having v be the angle offset from the x/y plane, it's the angle offset from the vertical (ie, a value of 30 will be 30 degrees lower than straight up and 60 degrees up from the wc3 plane).
JASS:
The x,y,z and roll inputs work exactly like the other two. However, instead of inputting two angles, for this function you input a target coordinate (fx,fy,fz) that you want the camera to face.
Example:
JASS:
call SetCameraCoord(0,0,400,0,-45,0)
This will cause the camera to be 400 above the center of the map, facing eastward and diagonally down at the ground, with a roll of 0.
Example 2:
JASS:
scope spinningthings initializer Init
globals
private real r = 0
endglobals
private function CALLBACK takes nothing returns nothing
set r = r + 3
if r > 360 then
set r = r - 360
endif
//call SetCameraCoord(300*Cos(bj_DEGTORAD*r),300*Sin(bj_DEGTORAD*r),456,180+r,-15,r)
//call SetCameraCoord(300*Cos(bj_DEGTORAD*r),300*Cos(bj_DEGTORAD*r),456,180+r,-15,r)
//call SetCameraCoord(300*Cos(bj_DEGTORAD*r),500*Sin(bj_DEGTORAD*r),456,180+r,-15,r)
//call SetCameraCoordTarget(300*Cos(bj_DEGTORAD*r),500*Sin(bj_DEGTORAD*r),456,0,0,356,r)
//This next one is a little long, but I'm soooo glad I made it. The calculus on the angles is a little big.
//call SetCameraCoord(800*Cos(bj_DEGTORAD*r),1300*Sin(bj_DEGTORAD*r),700 + 300*Cos(bj_DEGTORAD*r),bj_RADTODEG*Atan2(1300*Cos(bj_DEGTORAD*r),-800*Sin(bj_DEGTORAD*r)),bj_RADTODEG*Atan2(-300*Sin(bj_DEGTORAD*r),SquareRoot((-800*Sin(bj_DEGTORAD*r))*(-800*Sin(bj_DEGTORAD*r)) + (1300*Cos(bj_DEGTORAD*r))*(1300*Cos(bj_DEGTORAD*r)))),-45+20*Cos(2*bj_DEGTORAD*r))
endfunction
private function Actions takes nothing returns nothing
call TimerStart(CreateTimer(),.03,true,function CALLBACK)
endfunction
private function Init takes nothing returns nothing
local trigger t = CreateTrigger()
call TriggerRegisterPlayerChatEvent(t,Player(0),"-",true)
call TriggerAddAction(t,function Actions)
endfunction
endscope
The commented things in the callback will cause simple looping parametric movement around the map origin if uncommented.