Orbital Camera
This simple script allows to implement a camera that orbits arround the desired unit using the arrow keys.Main Script
JASS:
//! zinc
///////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////
// Orbital Camera
// (By IO)
// Requires
// -Last version of JassHelper
/////////////////////////////////////////////////////////////////
library OrbitalCamSystem {
//Configurable System Variables
constant real DELAY = 0.45; //smoothing factor
constant real ANGLE_OF_ATTACK = 150.0; //
constant real MIN_AOA = -20.0; //min angle of attack
constant real MAX_AOA = -80.0; //max angle of attack
constant real AOA_SENS = 4.0; //AOE change velocity
constant real ROTATION_SENS = 16.0; //Rotation Change Velocity
constant real DEFAULT_SENSITIVITY = 0.07; //Arrow Keys Sensitivity
constant real DEFAULT_DISTANCE = 1000.0; //default distance of camera
constant real DEFAULT_Z_DISTANCE = 128.0; //Height of camera
constant real FPS = 12.0; //Frame Rate
constant real CAM_ORIGIN = 0.0; //camera focus
public unit HERO[];
// Default
real DEF_AOA = -20;
//
public struct Camera extends array{
real rotation,angleOfAttack;
real sensitivity;
boolean Upressed,Dpressed,Lpressed,Rpressed;
boolean IsCameraActive;
location l;
static method onPressUp() -> boolean{
thistype this = GetPlayerId(GetTriggerPlayer());
this.Upressed=true;
return false;
}
static method onPressLeft() -> boolean{
thistype this = GetPlayerId(GetTriggerPlayer());
this.Lpressed=true;
return false;
}
static method onPressRight() -> boolean{
thistype this = GetPlayerId(GetTriggerPlayer());
this.Rpressed=true;
return false;
}
static method onPressDown() -> boolean{
thistype this = GetPlayerId(GetTriggerPlayer());
this.Dpressed=true;
return false;
}
static method onRelease() -> boolean{
thistype this = GetPlayerId(GetTriggerPlayer());
if (this.Upressed){
this.Upressed=false;
}
if (this.Dpressed){
this.Dpressed=false;
}
if (this.Lpressed){
this.Lpressed=false;
}
if (this.Rpressed){
this.Rpressed=false;
}
return false;
}
static method updatingControls(){
integer i=0;
thistype this = 0;
while (i<12){
this = i;
if ((this.Upressed)&&(this.angleOfAttack<MIN_AOA)){ this.angleOfAttack += AOA_SENS;}
if ((this.Dpressed)&&(this.angleOfAttack>MAX_AOA)){ this.angleOfAttack -= AOA_SENS; }
if (this.Lpressed){ this.rotation += ROTATION_SENS;}
if (this.Rpressed){ this.rotation -= ROTATION_SENS;}
if ((this.rotation > 360.0)||(this.rotation < -360)){this.rotation=0.0; }
i +=1;
}
}
static method forcingCamera(){
integer i=0;
thistype this = 0;
real z =0.0;
real x =0.0 , y=0.0;
real a =0.0,a2=0.0;
while (i<12){
this = i;
if (this.IsCameraActive){
if (Player(i)==GetLocalPlayer()){
a = GetUnitFacing(HERO[i])*bj_DEGTORAD;
x = GetUnitX(HERO[i]);
y = GetUnitY(HERO[i]);
MoveLocation(this.l,x,y);
z = GetLocationZ(this.l);
SetCameraField(CAMERA_FIELD_TARGET_DISTANCE,DEFAULT_DISTANCE, DELAY);
SetCameraField(CAMERA_FIELD_ANGLE_OF_ATTACK, this.angleOfAttack, DELAY);
SetCameraField(CAMERA_FIELD_ROTATION, this.rotation, DELAY);
SetCameraField(CAMERA_FIELD_ZOFFSET, GetCameraField(CAMERA_FIELD_ZOFFSET) + z - GetCameraTargetPositionZ() + DEFAULT_Z_DISTANCE, DELAY);
SetCameraField(CAMERA_FIELD_ZOFFSET, GetCameraField(CAMERA_FIELD_ZOFFSET) + z - GetCameraTargetPositionZ() + DEFAULT_Z_DISTANCE, DELAY);
SetCameraTargetController(HERO[i],CAM_ORIGIN*Cos(a),CAM_ORIGIN*Sin(a),false);
}
}
i +=1;
}
}
}
//GUI support
public function SupportGUI(){
integer i =0;
if(udg_UsingGUI){
while(i <= bj_MAX_PLAYERS){
HERO[i]=udg_Heroe[i+1];
i +=1;
}
}
}
function onInit (){
trigger t_up_press = CreateTrigger(), onOneSec= CreateTrigger();
trigger t_up_release = CreateTrigger(),t_down_press=CreateTrigger(),t_down_release=CreateTrigger(),t_left_press=CreateTrigger(),t_left_release=CreateTrigger()
,t_right_press = CreateTrigger(),t_right_release=CreateTrigger();
integer i = 0;
real fps = 1.0/FPS ;
Camera cam = 0;
while (i < bj_MAX_PLAYER_SLOTS){
if((GetPlayerSlotState(Player(i))== PLAYER_SLOT_STATE_PLAYING)&&( GetPlayerController(Player(i)) == MAP_CONTROL_USER )){
TriggerRegisterPlayerKeyEventBJ( t_up_press , Player(i), bj_KEYEVENTTYPE_DEPRESS, bj_KEYEVENTKEY_UP );
TriggerRegisterPlayerKeyEventBJ( t_up_release, Player(i), bj_KEYEVENTTYPE_RELEASE, bj_KEYEVENTKEY_UP );
TriggerRegisterPlayerKeyEventBJ( t_down_release, Player(i), bj_KEYEVENTTYPE_RELEASE, bj_KEYEVENTKEY_DOWN );
TriggerRegisterPlayerKeyEventBJ( t_down_press, Player(i), bj_KEYEVENTTYPE_DEPRESS, bj_KEYEVENTKEY_DOWN );
TriggerRegisterPlayerKeyEventBJ( t_left_release, Player(i), bj_KEYEVENTTYPE_RELEASE, bj_KEYEVENTKEY_LEFT );
TriggerRegisterPlayerKeyEventBJ( t_left_press, Player(i), bj_KEYEVENTTYPE_DEPRESS, bj_KEYEVENTKEY_LEFT);
TriggerRegisterPlayerKeyEventBJ( t_right_release, Player(i), bj_KEYEVENTTYPE_RELEASE, bj_KEYEVENTKEY_RIGHT );
TriggerRegisterPlayerKeyEventBJ( t_right_press, Player(i), bj_KEYEVENTTYPE_DEPRESS, bj_KEYEVENTKEY_RIGHT );
cam = i;
cam.angleOfAttack = DEF_AOA;
cam.l = Location(0.0,0.0);
}
i +=1;
}
TriggerRegisterTimerEvent(onOneSec, 1.0, false);
TriggerAddAction(onOneSec, function SupportGUI );
TriggerAddCondition(t_up_press, Condition(function Camera.onPressUp ));
TriggerAddCondition(t_up_release, Condition(function Camera.onRelease ));
TriggerAddCondition(t_down_press, Condition(function Camera.onPressDown ));
TriggerAddCondition(t_down_release, Condition(function Camera.onRelease ));
TriggerAddCondition(t_left_press, Condition(function Camera.onPressLeft ));
TriggerAddCondition(t_left_release, Condition(function Camera.onRelease ));
TriggerAddCondition(t_right_press, Condition(function Camera.onPressRight ));
TriggerAddCondition(t_right_release, Condition(function Camera.onRelease ));
TimerStart(CreateTimer(),fps ,true , function Camera.forcingCamera);
TimerStart(CreateTimer(),DEFAULT_SENSITIVITY ,true , function Camera.updatingControls);
}
}
//! endzinc
Snippet
JASS:
//! zinc
library CamControl requires OrbitalCamSystem {
/*
(snippet)
this script activates and deactivates the camera system using the ESC key
*/
function cond () -> boolean{
Camera cam =GetPlayerId(GetTriggerPlayer());
if (cam.IsCameraActive){
cam.IsCameraActive=false;
if(Player(GetPlayerId(GetTriggerPlayer()))==GetLocalPlayer()){
ResetToGameCamera(1.0);
}
}
else if (!cam.IsCameraActive) {
cam.IsCameraActive=true;
}
return false;
}
//===========================================================================
function onInit (){
integer i = 0;
trigger t = CreateTrigger( );
while (i <= bj_MAX_PLAYERS){
TriggerRegisterPlayerEvent(t, Player(i), EVENT_PLAYER_END_CINEMATIC);
i +=1;
}
TriggerAddCondition(t, Condition( function cond));
}
}
//! endzinc
PD: Press the Esc Key to Activate the camera in the test map...