- Joined
- Aug 18, 2013
- Messages
- 85
JASS:
//! zinc
library CameraSystem requires optional CameraKeyboardMovement
{
//////////////////////////////////////////////////////////////////////////
//
// Configuration area
// - Just default variables which the system will use when no other ones are specified by the user.
constant real CAMERA_DEFAULT_X = 0,
CAMERA_DEFAULT_Y = 0,
CAMERA_DEFAULT_ZANGLE = 350,
CAMERA_DEFAULT_ZHEIGHT = 190,
CAMERA_DEFAULT_ROTATION = 0,
CAMERA_DEFAULT_DISTANCE = 175,
// - This is tricky. It defines the weight the measurements of the z position have. This system measures
// out 4 locations to get a neat z height, 2 of them are at the unit's location and 2 are at the camera
// location which is a bit further away. Those values define which measure has more weight - if you have
// low terrain with less cliff heights you should probably give the unit's measurement more weight.
// If you don't understand a bit of what I'm trying to explain, just play around a bit with those values
// and look what effect they might have.
CAMERA_TARGET_WEIGHT = 1,
CAMERA_CAMERA_WEIGHT = 2 - CAMERA_TARGET_WEIGHT,
// - What difference the measures have, if you have really steep cliffs (I'm not talking about blizzard cliffs)
// you should probably decrease this.
CAMERA_ZDIST_MEASURE = 50,
// - Pretty much self-explaining. You don't really have to change anything here.
CAMERA_LOOP_INTERVAL = 0.01,
CAMERA_UPDATE_INTERVAL = 0.2;
//////////////////////////////////////////////////////////////////////////
//
// Struct area
public struct CAMERA
{
//////////////////////////////////////////////////////////////////////////
//
// Struct variable area
public
{
real x = CAMERA_DEFAULT_X, y = CAMERA_DEFAULT_Y,
zAngle = CAMERA_DEFAULT_ZANGLE, zHeight = CAMERA_DEFAULT_ZHEIGHT,
rotation = CAMERA_DEFAULT_ROTATION, distanceToTarget = CAMERA_DEFAULT_DISTANCE;
player applyFor = null;
unit toFollow = null;
}
private
{
integer node;
boolean activated = false;
static timer t = CreateTimer();
static integer count = 0;
static thistype data[];
static location loc = Location(0,0);
}
optional module CameraKeyboardMovement;
//////////////////////////////////////////////////////////////////////////
//
// Struct method area
static method create(player p) -> thistype
{
thistype this = thistype.allocate();
applyFor = p;
static if (thistype.movementInit.exists) { movementInit(); }
return this;
}
method apply()
{
if (count == 0)
TimerStart(t, CAMERA_LOOP_INTERVAL, true, static method thistype.cameraLoop);
data[count] = this;
node = count;
count += 1;
activated = true;
}
private static method cameraLoop()
{
real tX = 0, tY = 0, tZ[], tzAngle = 0, tzHeight = 0, tRotation = 0;
thistype this;
integer i = 0;
while (i < count)
{
this = data[i];
static if (thistype.movement.exists) { movement(); }
if (toFollow != null)
{
x = GetUnitX(toFollow); y = GetUnitY(toFollow);
tRotation = GetUnitFacing(toFollow)*bj_DEGTORAD;
tzHeight = GetUnitFlyHeight(toFollow);
}
tX = x; tY = y;
tX += CAMERA_ZDIST_MEASURE/2 * Cos(tRotation);
tY += CAMERA_ZDIST_MEASURE/2 * Sin(tRotation);
MoveLocation(loc, tX, tY);
tZ[0] = GetLocationZ(loc);
tX -= CAMERA_ZDIST_MEASURE * Cos(tRotation);
tY -= CAMERA_ZDIST_MEASURE * Sin(tRotation);
MoveLocation(loc, tX, tY);
tZ[1] = GetLocationZ(loc);
tX = GetCameraTargetPositionX() + CAMERA_ZDIST_MEASURE/2 * Cos(tRotation);
tY = GetCameraTargetPositionY() + CAMERA_ZDIST_MEASURE/2 * Sin(tRotation);
MoveLocation(loc, tX, tY);
tZ[2] = GetLocationZ(loc);
tX -= CAMERA_ZDIST_MEASURE * Cos(tRotation);
tY -= CAMERA_ZDIST_MEASURE * Sin(tRotation);
MoveLocation(loc, tX, tY);
tZ[3] = GetLocationZ(loc);
tZ[2] = ((tZ[0]-tZ[1])*CAMERA_TARGET_WEIGHT+(tZ[2]-tZ[3])*CAMERA_CAMERA_WEIGHT)/4;
tX = x; tY = y;
tRotation += rotation*bj_DEGTORAD;
tX -= (distanceToTarget+tZ[2]) * Cos(tRotation);
tY -= (distanceToTarget+tZ[2]) * Sin(tRotation);
MoveLocation(loc, tX, tY);
tzAngle = zAngle + tZ[2];
tzHeight += zHeight + GetCameraField(CAMERA_FIELD_ZOFFSET) + GetLocationZ(loc) + RAbsBJ(tZ[2]) - GetCameraEyePositionZ();
if (GetLocalPlayer() == applyFor)
{
PanCameraToTimed(tX, tY, CAMERA_UPDATE_INTERVAL);
SetCameraField(CAMERA_FIELD_ZOFFSET, tzHeight, CAMERA_UPDATE_INTERVAL);
SetCameraField(CAMERA_FIELD_ANGLE_OF_ATTACK, tzAngle, CAMERA_UPDATE_INTERVAL);
SetCameraField(CAMERA_FIELD_ROTATION, tRotation*bj_RADTODEG, CAMERA_UPDATE_INTERVAL);
SetCameraField(CAMERA_FIELD_TARGET_DISTANCE, distanceToTarget+tZ[2], CAMERA_UPDATE_INTERVAL);
}
i += 1;
}
}
method operator active() -> boolean
{ return activated; }
method operator active=(boolean b)
{
if (b && !activated)
apply();
else if (!b && activated)
{
data[node] = data[count-1];
data[node].node = node;
count -= 1;
if (count == 0)
PauseTimer(t);
activated = false;
}
}
method destroy()
{
if (activated)
{
data[node] = data[count-1];
data[node].node = node;
count -= 1;
if (count == 0)
PauseTimer(t);
}
deallocate();
}
}
}
//! endzinc
I want to get rid of this camera.
JASS:
CAMERA_LOOP_INTERVAL = 0.01,
CAMERA_UPDATE_INTERVAL = 0.2;
Changing these to "1000" would help me stop the camera from immediately panning to the unit. But I don't know how to create another trigger and edit these values.
Can I please get some help