|
» open
library DGUIcs uses ENGINE
globals
location GL = Location(0,0)
endglobals
function echo takes string message returns nothing
call DisplayTextToPlayer(GetLocalPlayer() , 0 , 0 , message)
endfunction
function GetZ takes real X,real Y returns real
call MoveLocation(GL , X , Y)
return GetLocationZ(GL)
endfunction
function GetUnitZ takes unit u,real X,real Y returns real
call MoveLocation(GL , X , Y)
return GetUnitFlyHeight(u) + GetLocationZ(GL)
endfunction
function SetUnitZ takes unit u,real z,real X,real Y returns nothing
call MoveLocation(GL , X , Y)
call SetUnitFlyHeight(u , z - GetLocationZ(GL) , 0)
endfunction
function GetUnitZun takes unit u returns real
call MoveLocation(GL , GetUnitX(u) , GetUnitY(u))
return GetUnitFlyHeight(u) + GetLocationZ(GL)
endfunction
function SetUnitZun takes unit u,real z returns nothing
call MoveLocation(GL , GetUnitX(u) , GetUnitY(u))
call SetUnitFlyHeight(u , z - GetLocationZ(GL) , 0)
endfunction
function SetUnitPos takes unit u,integer pos returns nothing
call SetUnitX(u , s__VECTOR3_x[pos])
call SetUnitY(u , s__VECTOR3_y[pos])
call MoveLocation(GL , s__VECTOR3_x[pos] , s__VECTOR3_y[pos])
call SetUnitFlyHeight(u , s__VECTOR3_z[pos] - GetLocationZ(GL) , 0)
endfunction
function SetUnitFly takes unit u returns nothing
call UnitAddAbility(u , 'Aave')
call UnitRemoveAbility(u , 'Aave')
endfunction
function SetUnitAloc takes unit u returns nothing
call UnitAddAbility(u , 'Aloc')
call UnitRemoveAbility(u , 'Aloc')
endfunction
endlibrary
//====================================================================
//====================================================================
//====================================================================
//====================================================================
//====================================================================
library Math
function R2I_n takes real r returns integer
local integer i = R2I(r)
if (r < I2R(i)+0.5) then
return i
else
return i+1
endif
endfunction
struct VECTOR3
static VECTOR3 Zero
static VECTOR3 oneX
static VECTOR3 oneY
static VECTOR3 oneZ
real x
real y
real z
static method New_0 takes nothing returns VECTOR3
local VECTOR3 this = VECTOR3.create()
set .x = 0
set .y = 0
set .z = 0
return this
endmethod
static method New_1 takes real x, real y, real z returns VECTOR3
local VECTOR3 this = VECTOR3.create()
set .x = x
set .y = y
set .z = z
return this
endmethod
static method New_2 takes VECTOR3 v returns VECTOR3
local VECTOR3 this = VECTOR3.create()
set .x = v.x
set .y = v.y
set .z = v.z
return this
endmethod
method SetValues takes real x, real y, real z returns VECTOR3
set .x = x
set .y = y
set .z = z
return this
endmethod
method Length takes nothing returns real
return SquareRoot(.x*.x+.y*.y+.z*.z)
endmethod
method LengthSq takes nothing returns real
return .x*.x+.y*.y+.z*.z
endmethod
method ToString takes nothing returns string
return "Vector3 id "+I2S(this) + "\nx = "+R2S(.x)+" y = "+R2S(.y)+" z = "+R2S(.z)
endmethod
endstruct
function Vec3Add takes VECTOR3 Output, VECTOR3 v1, VECTOR3 v2 returns VECTOR3
set Output.x = v1.x + v2.x
set Output.y = v1.y + v2.y
set Output.z = v1.z + v2.z
return Output
endfunction
function Vec3Subtract takes VECTOR3 Output, VECTOR3 v1, VECTOR3 v2 returns VECTOR3
set Output.x = v1.x - v2.x
set Output.y = v1.y - v2.y
set Output.z = v1.z - v2.z
return Output
endfunction
function Vec3Scale takes VECTOR3 Output, VECTOR3 v, real r returns VECTOR3
set Output.x = v.x * r
set Output.y = v.y * r
set Output.z = v.z * r
return Output
endfunction
function Vec3Division takes VECTOR3 Output, VECTOR3 v, real r returns VECTOR3
set Output.x = v.x / r
set Output.y = v.y / r
set Output.z = v.z / r
return Output
endfunction
function Vec3Length takes VECTOR3 v returns real
return SquareRoot(v.x*v.x+v.y*v.y+v.z*v.z)
endfunction
function Vec3LengthSq takes VECTOR3 v returns real
return v.x*v.x+v.y*v.y+v.z*v.z
endfunction
function Vec3Normalize takes VECTOR3 Output, VECTOR3 v returns VECTOR3
local real len = SquareRoot(v.x*v.x+v.y*v.y+v.z*v.z)
set Output.x = v.x/len
set Output.y = v.y/len
set Output.z = v.z/len
return Output
endfunction
function Vec3Dot takes VECTOR3 v1, VECTOR3 v2 returns real
return v1.x*v2.x+v1.y*v2.y+v1.z*v2.z
endfunction
function Vec3Cross takes VECTOR3 Output, VECTOR3 v1, VECTOR3 v2 returns VECTOR3
local real y = v1.z * v2.x - v1.x * v2.z
local real z = v1.x * v2.y - v1.y * v2.x
set Output.x = v1.y * v2.z - v1.z * v2.y
set Output.y = y
set Output.z = z
return Output
endfunction
function Vec3Transform_1 takes VECTOR3 Output, VECTOR3 v, MATRIX3 m returns VECTOR3
local real y = v.x*m.m12+v.y*m.m22+v.z*m.m32
local real z = v.x*m.m13+v.y*m.m23+v.z*m.m33
set Output.x = v.x*m.m11+v.y*m.m21+v.z*m.m31
set Output.y = y
set Output.z = z
return Output
endfunction
function Vec3Transform_2 takes VECTOR3 Output, VECTOR3 v, MATRIX4 m returns VECTOR3
local real y = v.x*m.m12+v.y*m.m22+v.z*m.m32+m.m42
local real z = v.x*m.m13+v.y*m.m23+v.z*m.m33+m.m43
local real w = v.x*m.m14+v.y*m.m24+v.z*m.m34+m.m44
set Output.x = (v.x*m.m11+v.y*m.m21+v.z*m.m31+m.m41)/w
set Output.y = y/w
set Output.z = z/w
return Output
endfunction
struct MATRIX3
static MATRIX3 Zero
static MATRIX3 E
real m11
real m12
real m13
real m21
real m22
real m23
real m31
real m32
real m33
static method New_0 takes nothing returns MATRIX3
local MATRIX3 this = MATRIX3.create()
set .m11 = 0
set .m12 = 0
set .m13 = 0
set .m21 = 0
set .m22 = 0
set .m23 = 0
set .m31 = 0
set .m32 = 0
set .m33 = 0
return this
endmethod
static method New_1 takes real r11, real r12, real r13, real r21, real r22, real r23, real r31, real r32, real r33 returns MATRIX3
local MATRIX3 this = MATRIX3.create()
set .m11 = r11
set .m12 = r12
set .m13 = r13
set .m21 = r21
set .m22 = r22
set .m23 = r23
set .m31 = r31
set .m32 = r32
set .m33 = r33
return this
endmethod
static method New_2 takes MATRIX3 m returns MATRIX3
local MATRIX3 this = MATRIX3.create()
set .m11 = m.m11
set .m12 = m.m12
set .m13 = m.m13
set .m21 = m.m21
set .m22 = m.m22
set .m23 = m.m23
set .m31 = m.m31
set .m32 = m.m32
set .m33 = m.m33
return this
endmethod
method SetValues takes real r11, real r12, real r13, real r21, real r22, real r23, real r31, real r32, real r33 returns MATRIX3
set .m11 = r11
set .m12 = r12
set .m13 = r13
set .m21 = r21
set .m22 = r22
set .m23 = r23
set .m31 = r31
set .m32 = r32
set .m33 = r33
return this
endmethod
method ToString takes nothing returns string
return "Matrux3 id "+I2S(this)+"\n"+R2S(.m11)+" "+R2S(.m12)+" "+R2S(.m13)+"\n"+R2S(.m21)+" "+R2S(.m22)+" "+R2S(.m23)+"\n"+R2S(.m31)+" "+R2S(.m32)+" "+R2S(.m33)
endmethod
endstruct
function Matrix3Multiply takes MATRIX3 Output, MATRIX3 M1, MATRIX3 M2 returns MATRIX3
return Output.SetValues(M1.m11*M2.m11+M1.m21*M2.m12+M1.m31*M2.m13,M1.m12*M2.m11+M1.m22*M2.m12+M1.m32*M2.m13,M1.m13*M2.m11+M1.m23*M2.m12+M1.m33*M2.m13,M1.m11*M2.m21+M1.m21*M2.m22+M1.m31*M2.m23,M1.m12*M2.m21+M1.m22*M2.m22+M1.m32*M2.m23,M1.m13*M2.m21+M1.m23*M2.m22+M1.m33*M2.m23,M1.m11*M2.m31+M1.m21*M2.m32+M1.m31*M2.m33,M1.m12*M2.m31+M1.m22*M2.m32+M1.m32*M2.m33,M1.m13*M2.m31+M1.m23*M2.m32+M1.m33*M2.m33)
endfunction
function Matrix3Scaling takes MATRIX3 Output, real x, real y, real z returns MATRIX3
return Output.SetValues(x,0,0,0,y,0,0,0,z)
endfunction
function Matrix3RotationX takes MATRIX3 Output, real a returns MATRIX3
return Output.SetValues(1,0,0,0,Cos(a),-Sin(a),0,Sin(a),Cos(a))
endfunction
function Matrix3RotationY takes MATRIX3 Output, real a returns MATRIX3
return Output.SetValues(Cos(a),0,Sin(a),0,1,0,-Sin(a),0,Cos(a))
endfunction
function Matrix3RotationZ takes MATRIX3 Output, real a returns MATRIX3
return Output.SetValues(Cos(a),-Sin(a),0,Sin(a),Cos(a),0,0,0,1)
endfunction
function Matrix3RotationAxis takes MATRIX3 Output, VECTOR3 v, real a returns MATRIX3
local real cosa = Cos(a)
local real sina = Sin(a)
return Output.SetValues(cosa+(1-cosa)*v.x*v.x,(1-cosa)*v.x*v.y-sina*v.z,(1-cosa)*v.x*v.z+sina*v.y,(1-cosa)*v.y*v.x+sina*v.z,cosa+(1-cosa)*v.y*v.y,(1-cosa)*v.y*v.z-sina*v.x,(1-cosa)*v.z*v.x-sina*v.y,(1-cosa)*v.z*v.y+sina*v.x,cosa+(1-cosa)*v.z*v.z)
endfunction
function Matrix3RotationYawPitchRoll takes MATRIX3 Output, real Yaw, real Pitch, real Roll returns MATRIX3
local real cosa = Cos(Yaw)
local real sina = Sin(Yaw)
local real cosb = Cos(Pitch)
local real sinb = Sin(Pitch)
local real cosy = Cos(Roll)
local real siny = Sin(Roll)
return Output.SetValues(cosa*cosb,cosa*sinb*siny-sina*cosy,cosa*sinb*cosy+sina*siny,sina*cosb,sina*sinb*siny+cosa*cosy,sina*sinb*cosy-cosa*siny,-sinb,cosb*siny,cosb*cosy)
endfunction
struct MATRIX4
static MATRIX4 Zero
static MATRIX4 E
real m11
real m12
real m13
real m14
real m21
real m22
real m23
real m24
real m31
real m32
real m33
real m34
real m41
real m42
real m43
real m44
static method New_0 takes nothing returns MATRIX4
local MATRIX4 this = MATRIX4.create()
set .m11 = 0
set .m12 = 0
set .m13 = 0
set .m14 = 0
set .m21 = 0
set .m22 = 0
set .m23 = 0
set .m24 = 0
set .m31 = 0
set .m32 = 0
set .m33 = 0
set .m34 = 0
set .m41 = 0
set .m42 = 0
set .m43 = 0
set .m44 = 0
return this
endmethod
static method New_1 takes real r11, real r12, real r13, real r14, real r21, real r22, real r23, real r24, real r31, real r32, real r33, real r34, real r41, real r42, real r43, real r44 returns MATRIX4
local MATRIX4 this = MATRIX4.create()
set .m11 = r11
set .m12 = r12
set .m13 = r13
set .m14 = r14
set .m21 = r21
set .m22 = r22
set .m23 = r23
set .m24 = r24
set .m31 = r31
set .m32 = r32
set .m33 = r33
set .m34 = r34
set .m41 = r41
set .m42 = r42
set .m43 = r43
set .m44 = r44
return this
endmethod
static method New_2 takes MATRIX4 m returns MATRIX4
local MATRIX4 this = MATRIX4.create()
set .m11 = m.m11
set .m12 = m.m12
set .m13 = m.m13
set .m14 = m.m14
set .m21 = m.m21
set .m22 = m.m22
set .m23 = m.m23
set .m24 = m.m24
set .m31 = m.m31
set .m32 = m.m32
set .m33 = m.m33
set .m34 = m.m34
set .m41 = m.m41
set .m42 = m.m42
set .m43 = m.m43
set .m44 = m.m44
return this
endmethod
static method New_3 takes MATRIX3 m returns MATRIX4
local MATRIX4 this = MATRIX4.create()
set .m11 = m.m11
set .m12 = m.m12
set .m13 = m.m13
set .m14 = 0
set .m21 = m.m21
set .m22 = m.m22
set .m23 = m.m23
set .m24 = 0
set .m31 = m.m31
set .m32 = m.m32
set .m33 = m.m33
set .m34 = 0
set .m41 = 0
set .m42 = 0
set .m43 = 0
set .m44 = 1
return this
endmethod
method SetValues takes real r11, real r12, real r13, real r14, real r21, real r22, real r23, real r24, real r31, real r32, real r33, real r34, real r41, real r42, real r43, real r44 returns MATRIX4
set .m11 = r11
set .m12 = r12
set .m13 = r13
set .m14 = r14
set .m21 = r21
set .m22 = r22
set .m23 = r23
set .m24 = r24
set .m31 = r31
set .m32 = r32
set .m33 = r33
set .m34 = r34
set .m41 = r41
set .m42 = r42
set .m43 = r43
set .m44 = r44
return this
endmethod
method ToString takes nothing returns string
return "Matrux4 id "+I2S(this)+"\n"+R2S(.m11)+" "+R2S(.m12)+" "+R2S(.m13)+" "+R2S(.m14)+"\n"+R2S(.m21)+" "+R2S(.m22)+" "+R2S(.m23)+" "+R2S(.m24)+"\n"+R2S(.m31)+" "+R2S(.m32)+" "+R2S(.m33)+" "+R2S(.m34)+"\n"+R2S(.m41)+" "+R2S(.m42)+" "+R2S(.m43)+" "+R2S(.m44)
endmethod
endstruct
function Matrix4Multiply takes MATRIX4 Output, MATRIX4 M1, MATRIX4 M2 returns MATRIX4
return Output.SetValues(M1.m11*M2.m11+M1.m21*M2.m12+M1.m31*M2.m13+M1.m41*M2.m14,M1.m12*M2.m11+M1.m22*M2.m12+M1.m32*M2.m13+M1.m42*M2.m14,M1.m13*M2.m11+M1.m23*M2.m12+M1.m33*M2.m13+M1.m43*M2.m14,M1.m14*M2.m11+M1.m24*M2.m12+M1.m34*M2.m13+M1.m44*M2.m14,M1.m11*M2.m21+M1.m21*M2.m22+M1.m31*M2.m23+M1.m41*M2.m24,M1.m12*M2.m21+M1.m22*M2.m22+M1.m32*M2.m23+M1.m42*M2.m24,M1.m13*M2.m21+M1.m23*M2.m22+M1.m33*M2.m23+M1.m43*M2.m24,M1.m14*M2.m21+M1.m24*M2.m22+M1.m34*M2.m23+M1.m44*M2.m24,M1.m11*M2.m31+M1.m21*M2.m32+M1.m31*M2.m33+M1.m41*M2.m34,M1.m12*M2.m31+M1.m22*M2.m32+M1.m32*M2.m33+M1.m42*M2.m34,M1.m13*M2.m31+M1.m23*M2.m32+M1.m33*M2.m33+M1.m43*M2.m34,M1.m14*M2.m31+M1.m24*M2.m32+M1.m34*M2.m33+M1.m44*M2.m34,M1.m11*M2.m41+M1.m21*M2.m42+M1.m31*M2.m43+M1.m41*M2.m44,M1.m12*M2.m41+M1.m22*M2.m42+M1.m32*M2.m43+M1.m42*M2.m44,M1.m13*M2.m41+M1.m23*M2.m42+M1.m33*M2.m43+M1.m43*M2.m44,M1.m14*M2.m41+M1.m24*M2.m42+M1.m34*M2.m43+M1.m44*M2.m44)
endfunction
function Math_Init takes nothing returns nothing
set VECTOR3.Zero = VECTOR3.New_0()
set VECTOR3.oneX = VECTOR3.New_1(1,0,0)
set VECTOR3.oneY = VECTOR3.New_1(0,1,0)
set VECTOR3.oneZ = VECTOR3.New_1(0,0,1)
set MATRIX3.Zero = MATRIX3.New_0()
set MATRIX3.E = MATRIX3.New_1(1,0,0,0,1,0,0,0,1)
set MATRIX4.Zero = MATRIX4.New_0()
set MATRIX4.E = MATRIX4.New_1(1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1)
endfunction
endlibrary
//====================================================================
//====================================================================
//====================================================================
//====================================================================
//====================================================================
library Camera requires Math, DGUIcs
globals
private constant integer TypeUnit = LINK_DGUI_TYPEUNIT
private location GL4Cam = Location(0,0)
private unit AtUnit = null
private real DeltaZ = 0
endglobals
globals
constant real WidthScreen = 0.544
constant real HeightScreen = 0.302
constant real AspectRatio = WidthScreen/HeightScreen
endglobals
private function Matrix4Perspective1 takes MATRIX4 Output, real fovy, real Aspect, real zn, real zf returns MATRIX4
return Output.SetValues(2*zn/fovy,0,0,0,0,2*zn/Aspect,0,0,0,0,zf/(zf-zn),1,0,0,zn*zf/(zn-zf),0)
endfunction
private function Matrix4Perspective2 takes MATRIX4 Output, real n, real f, real r, real l, real t, real b returns MATRIX4
return Output.SetValues(2*n/(r-l), 0, (r+l)/(r-l), 0, 0, 2*n/(t-b), (t+b)/(t-b), 0, 0, 0, -(f+n)/(f-n), -2*f*n/(f-n), 0, 0, -1, 0)
endfunction
private function Matrix4Look takes MATRIX4 Output, VECTOR3 PosCamera, VECTOR3 AxisX, VECTOR3 AxisY, VECTOR3 AxisZ returns MATRIX4
return Output.SetValues(AxisX.x,AxisY.x,AxisZ.x,0,AxisX.y,AxisY.y,AxisZ.y,0,AxisX.z,AxisY.z,AxisZ.z,0,-Vec3Dot(AxisX, PosCamera),-Vec3Dot(AxisY, PosCamera),-Vec3Dot(AxisZ, PosCamera),1)
endfunction
struct CAMERA
VECTOR3 Eye
VECTOR3 At
real Distance
real Yaw
real Pitch
real Roll
VECTOR3 AxisX
VECTOR3 AxisY
VECTOR3 AxisZ
private MATRIX4 View
private MATRIX4 Projection
private boolean change
integer CostumValue
method Win2World takes real X, real Y, real Range returns VECTOR3
local VECTOR3 Output = VECTOR3.create()
set Output.x = .Eye.x+.AxisZ.x*Range+X*.AxisX.x*WidthScreen*Range+Y*.AxisY.x*HeightScreen*Range
set Output.y = .Eye.y+.AxisZ.y*Range+X*.AxisX.y*WidthScreen*Range+Y*.AxisY.y*HeightScreen*Range
set Output.z = .Eye.z+.AxisZ.z*Range+X*.AxisX.z*WidthScreen*Range+Y*.AxisY.z*HeightScreen*Range
return Output
endmethod
method World2Win takes real X, real Y, real Z returns VECTOR3
local VECTOR3 Pos = VECTOR3.New_1(X, Y, Z)
local boolean b
call Vec3Transform_2(Pos, Pos, .View)
set b = Pos.z < 0
call Vec3Transform_2(Pos, Pos, .Projection)
if b then
set Pos.z = -Pos.z
endif
return Pos
endmethod
private method UpdateDistanceYawPitch takes nothing returns nothing
local real dx = .At.x-.Eye.x
local real dy = .At.y-.Eye.y
local real dz = .At.z-.Eye.z
local real len2d
set .Distance = SquareRoot(dx*dx+dy*dy+dz*dz)
set .Yaw = Atan2(dy, dx)
set len2d = SquareRoot(dx*dx+dy*dy)
set .Pitch = Atan2(dz, len2d)
endmethod
private method UpdateAxisMatrix takes nothing returns nothing
local MATRIX3 mat
call Vec3Normalize(.AxisZ, Vec3Subtract(.AxisZ, .At, .Eye))
set mat = Matrix3RotationAxis(MATRIX3.create(), .AxisZ, -.Roll)
call Vec3Normalize(.AxisX, Vec3Cross(.AxisX, .AxisZ, VECTOR3.oneZ))
call Vec3Transform_1(.AxisY, Vec3Cross(.AxisY, .AxisX, .AxisZ), mat)
call Vec3Transform_1(.AxisX, .AxisX, mat)
call Matrix4Look(.View, .Eye, .AxisX, .AxisY, .AxisZ)
call mat.destroy()
endmethod
method ApplyCameraForPlayer takes player p, boolean IgnorChange returns boolean
if GetLocalPlayer() == p then
call SetCameraField(CAMERA_FIELD_ROTATION, .Yaw*bj_RADTODEG, 0)
call SetCameraField(CAMERA_FIELD_ANGLE_OF_ATTACK, .Pitch*bj_RADTODEG, 0)
call SetCameraField(CAMERA_FIELD_ROLL, .Roll*bj_RADTODEG, 0)
call SetCameraField(CAMERA_FIELD_TARGET_DISTANCE, .Distance, 0)
call SetCameraTargetController(AtUnit, .At.x, .At.y, false)
call SetCameraField(CAMERA_FIELD_ZOFFSET, .At.z-DeltaZ, 0)
endif
if .change or IgnorChange then
set .change = false
return true
endif
return false
endmethod
method SetPosition takes real x, real y, real z returns nothing
local real dx = x-.At.x
local real dy = y-.At.y
local real dz = z-.At.z
set .Eye.x = .Eye.x+dx
set .Eye.y = .Eye.y+dy
set .Eye.z = .Eye.z+dz
set .At.x = x
set .At.y = y
set .At.z = z
set .change = true
endmethod
method SetEyeAndAt takes real ex, real ey, real ez, real tx, real ty, real tz returns nothing
set .Eye.x = ex
set .Eye.y = ey
set .Eye.z = ez
set .At.x = tx
set .At.y = ty
set .At.z = tz
call .UpdateDistanceYawPitch()
call .UpdateAxisMatrix()
set .change = true
endmethod
method SetYawPitchRoll takes real yaw, real pitch, real roll, boolean EyeLock returns nothing
local real Z = .Distance*Sin(pitch)
local real XY = .Distance*Cos(pitch)
local real X = XY*Cos(yaw)
local real Y = XY*Sin(yaw)
set .Yaw = yaw
set .Pitch = pitch
set .Roll = roll
if EyeLock then
set .At.x = .Eye.x+X
set .At.y = .Eye.y+Y
set .At.z = .Eye.z+Z
else
set .Eye.x = .At.x-X
set .Eye.y = .At.y-Y
set .Eye.z = .At.z-Z
endif
call .UpdateAxisMatrix()
set .change = true
endmethod
static method New takes nothing returns CAMERA
local CAMERA this = CAMERA.create()
set .CostumValue = 0
set .change = true
set .Eye = VECTOR3.New_1(0.0,-922.668,DeltaZ+1367.912)
set .At = VECTOR3.New_1(0, 0, DeltaZ)
set .Distance = 0
set .Yaw = 0
set .Pitch = 0
set .Roll = 0
set .AxisX = VECTOR3.create()
set .AxisY = VECTOR3.create()
set .AxisZ = VECTOR3.create()
set .View = MATRIX4.create()
set .Projection = Matrix4Perspective2(MATRIX4.create(), 0.5, 10000, -WidthScreen/2, WidthScreen/2, -HeightScreen/2, HeightScreen/2)
call .UpdateDistanceYawPitch()
call .UpdateAxisMatrix()
return this
endmethod
method Delete takes nothing returns nothing
call .Eye.destroy()
call .At.destroy()
call .AxisX.destroy()
call .AxisY.destroy()
call .AxisZ.destroy()
call .View.destroy()
call .Projection.destroy()
call this.destroy()
endmethod
endstruct
globals
private real TempX = 0
private real TempY = 0
endglobals
private function InitDeltaZ_Timer takes nothing returns nothing
set DeltaZ = GetCameraTargetPositionZ()
call SetCameraPosition(TempX, TempY)
call DestroyTimer(GetExpiredTimer())
endfunction
function InitDeltaZ takes nothing returns nothing
set TempX = GetCameraTargetPositionX()
set TempY = GetCameraTargetPositionY()
call SetCameraPosition(0, 0)
call TimerStart(CreateTimer(), 0.04, false, function InitDeltaZ_Timer)
endfunction
function Camera_Init takes nothing returns nothing
set AtUnit = CreateUnit(Player(15), TypeUnit, 0, 0, 0)
call ShowUnit(AtUnit, false)
call InitDeltaZ()
endfunction
endlibrary
//====================================================================
//====================================================================
//====================================================================
//====================================================================
//====================================================================
library DGUI uses Math, Camera, DGUIcs
#define private TypeUnit = LINK_DGUI_TYPEUNIT
private BUTTON TriggerButton
private location GL4DGUI = Location(0,0)
private bool SHOW = false
real BUTTON_SIZE_BIG = 0.171
real BUTTON_SIZE_MEDIUM = 0.124
real BUTTON_SIZE_SMALL = 0.08
int GetDGUIut() {
return TypeUnit
}
BUTTON GetTriggerButton() {
return TriggerButton
}
private real GetZ4DGUI(real X, real Y) {
MoveLocation(GL4DGUI, X, Y)
return GetLocationZ(GL4DGUI)
}
private int FineIndexAnimeModel(real w, real h, real z) {
real W = w*WidthScreen*z
real H = h*HeightScreen*z
real anim
if (H<W) {
anim = 5*(W/H-1)
return R2I_n(anim)
} else {
anim = 5*(H/W-1)
if (anim >= 0.5) {
return 50+R2I_n(anim)
}
}
return 0
}
private real FineSizeModel(real w, real h, real z) {
real W = w*WidthScreen*z
real H = h*HeightScreen*z
if (H<W) {
return H/2.0
} else {
return W/2.0
}
}
struct BUTTON {
static BUTTON array All
static int Count = 0
private int index
private CAMERA Camera
int customvalue
real centerx //
real centery //
private real minx
private real maxx
private real miny
private real maxy
private real z
private unit picture
private int indexanim
private effect model
private int texture
trigger trigLclick
trigger trigRclick
bool show
static BUTTON New(CAMERA Cam, real minx, real maxy, real W, real H, real z, boolean b, integer texture) {
BUTTON this = BUTTON.create()
destructable tree = CreateDestructable(texture,0,0,0,1,0)
.Camera = Cam
.texture = texture
.minx = minx
.maxx = minx+W
.maxy = maxy
.miny = maxy-H
.z = 100.2+z
.centerx = minx+W/2.0
.centery = maxy-H/2.0
.show = b
.trigLclick = CreateTrigger()
.trigRclick = CreateTrigger()
.picture = CreateUnit(Player(15), TypeUnit, 0, 0, 0)
IssueTargetOrder(.picture,"grabtree",tree)
.indexanim = FineIndexAnimeModel(W, H, .z)
SetUnitAnimationByIndex(.picture, .indexanim)
SetUnitScale(.picture, FineSizeModel(W, H, .z), 0, 0)
UnitAddAbility(.picture, 'Aave')
UnitRemoveAbility(.picture, 'Aave')
ShowUnit(.picture, b)
PauseUnit(.picture, true)
.All[.Count] = this
.index = .Count
.Count ++
RemoveDestructable(tree)
tree = null
return this
}
void ReloadTexture() {
destructable tree = CreateDestructable(.texture,GetUnitX(.picture),GetUnitY(.picture),0,1,0)
real W = (.centerx - .minx)*2.0
real H = (.maxy - .centery)*2.0
PauseUnit(.picture, false)
IssueTargetOrder(.picture,"grabtree",tree)
Sleep(0.1)
.indexanim = FineIndexAnimeModel(W, H, .z)
SetUnitAnimationByIndex(.picture, .indexanim)
SetUnitScale(.picture, FineSizeModel(W, H, .z), 0, 0)
RemoveDestructable(tree)
PauseUnit(.picture, true)
tree = null
}
triggeraction AddActionL(code funct) {
return TriggerAddAction(.trigLclick, funct)
}
void RemoveActionL(triggeraction action) {
TriggerRemoveAction(.trigLclick, action)
}
triggeraction AddActionR(code funct) {
return TriggerAddAction(.trigRclick, funct)
}
void RemoveActionR(triggeraction action) {
TriggerRemoveAction(.trigRclick, action)
}
void Delete() {
DestroyTrigger(.trigLclick)
DestroyTrigger(.trigRclick)
RemoveUnit(.picture)
.All[.index] = .All[.Count]
.All[.index].index = .index
.Count --
}
void Update() {
VECTOR3 Pos = .Camera.Win2World(.centerx, .centery, .z)
ShowUnit(.picture, (.show and SHOW))
SetUnitX(.picture, Pos.x)
SetUnitY(.picture, Pos.y)
MoveLocation(GL4DGUI, Pos.x, Pos.y)
SetUnitFlyHeight(.picture, Pos.z-GetLocationZ(GL4DGUI), 0)
Pos.destroy()
}
void Show(bool show) {
ShowUnit(.picture, show and SHOW)
.show = show
if (show) {
SetUnitAnimationByIndex(.picture, .indexanim)
}
}
void SetColor(int R, int G, int B, int A) {
SetUnitVertexColor(.picture,R,G,B,A)
}
bool IsClick(unit u) {
return .picture == u
}
bool IsClickEx(real x, real y) {
return .minx < x and x < .maxx and .miny < y and y < .maxy
}
void ClickL() {
TriggerButton = this
TriggerExecute(.trigLclick)
}
void ClickR() {
TriggerButton = this
TriggerExecute(.trigRclick)
}
}
struct PICTURE {
static PICTURE array All
static int Count = 0
private int index
private CAMERA Camera
private real centerx
private real centery
private real h
private real w
private real z
private unit picture
private int indexanim
private int texture
bool show
static PICTURE New(CAMERA Cam, real minx, real maxy, real W, real H, real z, bool b, int texture) {
PICTURE this = PICTURE.create()
destructable tree = CreateDestructable(texture,0,0,0,1,0)
.Camera = Cam
.centerx = minx+W/2
.centery = maxy-H/2
.h = H
.w = W
.z = 100.2+z
.texture=texture
.show = b
.picture = CreateUnit(Player(15), TypeUnit, 0, 0, 0)
IssueTargetOrder(.picture, "grabtree", tree)
.indexanim = FineIndexAnimeModel(W, H, .z)
SetUnitAnimationByIndex(.picture, .indexanim)
SetUnitScale(.picture, FineSizeModel(W, H, .z), 0, 0)
UnitAddAbility(.picture, 'Aave')
UnitRemoveAbility(.picture, 'Aave')
UnitAddAbility(.picture, 'Aloc')
UnitRemoveAbility(.picture, 'Aloc')
ShowUnit(.picture, b)
PauseUnit(.picture, true)
.All[.Count] = this
.index = .Count
.Count ++
RemoveDestructable(tree)
tree = null
return this
}
void Delete() {
RemoveUnit(.picture)
.All[.index] = .All[.Count]
.All[.index].index = .index
.Count --
}
void Update() {
VECTOR3 Pos = .Camera.Win2World(.centerx, .centery, .z)
ShowUnit(.picture, (.show and SHOW))
SetUnitX(.picture, Pos.x)
SetUnitY(.picture, Pos.y)
MoveLocation(GL4DGUI, Pos.x, Pos.y)
SetUnitFlyHeight(.picture, Pos.z-GetLocationZ(GL4DGUI), 0)
Pos.destroy()
}
void ReloadTexture() {
destructable tree = CreateDestructable(.texture,GetUnitX(.picture),GetUnitY(.picture),0,1,0)
PauseUnit(.picture, false)
IssueTargetOrder(.picture,"grabtree",tree)
Sleep(0.1)
.indexanim = FineIndexAnimeModel(.w, .h, .z)
SetUnitAnimationByIndex(.picture, .indexanim)
SetUnitScale(.picture, FineSizeModel(.w, .h, .z), 0, 0)
RemoveDestructable(tree)
PauseUnit(.picture, true)
}
void Show(bool show) {
ShowUnit(.picture, show and SHOW)
.show = show
if (show) {
SetUnitAnimationByIndex(.picture, .indexanim)
}
}
void SetColor(int R, int G, int B, int A) {
SetUnitVertexColor(.picture,R,G,B,A)
}
}
struct TEXT {
static TEXT array All
static int Count = 0
private int index
private CAMERA Camera
private real minx
private real maxy
private real z
texttag text
string st
real h
bool show
void DebugInfo() {
// T[0]: minx=0.0,maxy=0.0
debug_msg("T["+I2S(.index)+"]: "+"minx="+R2S(.minx)+","+"maxy="+R2S(.maxy))
if(.st == null) {
debug_msg(" text == null" )
}
if(.text == null) {
debug_msg(" texttag == null!")
}
}
static TEXT New(CAMERA Cam, real minx, real maxy, real z, boolean b) {
TEXT this = TEXT.create()
.Camera = Cam
.minx = minx
.maxy = maxy
.z = 100+z
.show = b
.st = null
.text = CreateTextTag()
SetTextTagVisibility(.text, b)
SetTextTagPermanent(.text,true)
.All[.Count] = this
.index = .Count
.Count ++
return this
}
void Delete() {
DestroyTextTag(.text)
.All[.index] = .All[.Count]
.All[.index].index = .index
.Count --
}
void Update() {
local VECTOR3 Pos = .Camera.Win2World(.minx, .maxy, .z)
call SetTextTagPos(.text, Pos.x, Pos.y, Pos.z-GetZ4DGUI(Pos.x,Pos.y))
call SetTextTagVisibility(.text, (.show and SHOW))
call Pos.destroy()
}
void Show(bool show) {
if (.show != show) {
SetTextTagVisibility(.text, show and SHOW)
.show = show
}
}
void SetText(string t, real h) {
.h = h
if(t != null) {
.st = t
SetTextTagText(.text,t,h)
}
}
void ClearTexttag() {
if (.text != null) {
DestroyTextTag(.text)
.text = null
}
}
void ReloadText() {
if (.text != null) {
DestroyTextTag(.text)
.text = null
}
.text = CreateTextTag()
SetTextTagPermanent(.text,true)
SetTextTagText(.text,.st,.h)
SetTextTagVisibility(.text, true)
.Update()
}
}
//====================================================================
void DGUIUpdate(bool but, bool pic, bool tex) {
int i=0
if (but) {
i=0
whilenot (i >= BUTTON.Count) {
if (BUTTON.All[i].show) { BUTTON.All[i].Update() }
i++
}
}
if (pic) {
i=0
whilenot (i >= PICTURE.Count) {
if (PICTURE.All[i].show) { PICTURE.All[i].Update() }
i++
}
}
if (tex) {
i=0
whilenot (i >= TEXT.Count) {
if (TEXT.All[i].show) { TEXT.All[i].Update() }
i++
}
}
}
void DGUIshow(bool flag) {
SHOW = flag
DGUIUpdate(true,true,true)
}
bool DGUIClick(unit u, boolean IsLeft) {
int i = 0
whilenot (i >= BUTTON.Count) {
if (BUTTON.All[i].show and BUTTON.All[i].IsClick(u)){
if (IsLeft) {
BUTTON.All[i].ClickL()
} else {
BUTTON.All[i].ClickR()
}
return true
}
i++
}
return false
}
bool DGUIClickEx (real x, real y, boolean IsLeft) {
int i = 0
whilenot (i >= BUTTON.Count) {
if (BUTTON.All[i].show and BUTTON.All[i].IsClickEx(x, y)) {
if (IsLeft) {
BUTTON.All[i].ClickL()
} else {
BUTTON.All[i].ClickR()
}
return true
}
i++
}
return false
}
//====================================================================
//====================================================================
private BUTTON reload_b
private PICTURE reload_p
void DGUI_Reload_B() {
reload_b.ReloadTexture()
}
void DGUI_Reload_P() {
reload_p.ReloadTexture()
}
void DGUI_Reload() {
int i=0
whilenot(i >= TEXT.Count) {
TEXT.All[i].ReloadText()
//TEXT.All[i].DebugInfo()
i++
}
debug_msg("TEXT reloaded: " + I2S(TEXT.Count))
i=0
whilenot(i >= BUTTON.Count) {
reload_b = BUTTON.All[i]
ThreadStart(DGUI_Reload_B)
i++
}
debug_msg("BUTTON reloaded: " + I2S(BUTTON.Count))
i=0
whilenot(i >= PICTURE.Count) {
reload_p = PICTURE.All[i]
ThreadStart(DGUI_Reload_P)
i++
}
debug_msg("PICTURE reloaded: " + I2S(PICTURE.Count))
DestroyTimer(GetExpiredTimer())
}
void DGUI_onload() {
initmsg("Reloading DGUI..")
TimerStart(CreateTimer(),0.05,false,function DGUI_Reload)
}
void DGUI_aftersave() {
initmsg("Reloading DGUI..")
int i=0
whilenot(i >= TEXT.Count) {
TEXT.All[i].ReloadText()
i++
}
}
void DGUI_onsave() {
initmsg("Cleaning DGUI..")
int i=0
whilenot(i >= TEXT.Count) {
TEXT.All[i].ClearTexttag()
i++
}
}
//====================================================================
//====================================================================
//=========================== MAIN INIT ==============================
void DGUI_Libs_Init() {
Camera_Init()
Math_Init()
}
endlibrary
моя версия дгуи )
ScorpioT1000 добавил:
если что, она нерабочая, т.е. требует дополнительные функции, но тут есть новые вещи, которые могут тебе пригодиться как копипаста)
ScorpioT1000 добавил:
например
void ReloadText() {
if (.text != null) {
DestroyTextTag(.text)
.text = null
}
.text = CreateTextTag()
SetTextTagPermanent(.text,true)
SetTextTagText(.text,.st,.h)
SetTextTagVisibility(.text, true)
.Update()
}
|