|
楼主 |
发表于 2010-2-18 17:12:38
|
显示全部楼层
代码是使用的Znic,我把需要展示的一段代码给翻出来,大家凑合看看吧。
[jass]
function BagSys__Camera_get takes nothing returns integer
local integer x=BagSys__Cameranum
if ( x < 8191 ) then
if ( BagSys__Camerasto[x] != 0 ) then
set BagSys__Cameranum=BagSys__Camerasto[x]
else
set BagSys__Cameranum=x + 1
endif
return x
endif
return 0
endfunction
function BagSys__Camera_del takes integer this returns nothing
if ( this > 0 ) then
set BagSys__Camerasto[this]=BagSys__Cameranum
set BagSys__Cameranum=this
endif
endfunction
这个函数是给玩家p创建一个镜头的数据,用来计算物品栏的位置用的。
function BagSys__CreateCamera_ForPlayer takes integer p returns integer
local integer x=BagSys__Camera_get()
set BagSys__Camera_p[p]=x
set BagSys__Camera_At[x]=BagSys__Camera_get()
set BagSys__Camera_Eye[x]=BagSys__Camera_get()
set BagSys__Camera_AxisX[x]=BagSys__Camera_get()
set BagSys__Camera_AxisY[x]=BagSys__Camera_get()
set BagSys__Camera_AxisZ[x]=BagSys__Camera_get()
return x
endfunction
[/jass]
[jass]
function BagSys__GetTerrainZ takes real x,real y returns real
call MoveLocation(BagSys__GL, x, y)
return GetLocationZ(BagSys__GL)
endfunction
function BagSys__Approximately takes real v1,real v2,real s returns boolean
return ( v2 - s < v1 ) and ( v1 < v2 + s )
endfunction
function BagSys__Vec3Normalize takes integer Output,integer v returns integer
local real len=SquareRoot(BagSys__Camera_x[v] * BagSys__Camera_x[v] + BagSys__Camera_y[v] * BagSys__Camera_y[v] + BagSys__Camera_z[v] * BagSys__Camera_z[v])
set BagSys__Camera_x[Output]=BagSys__Camera_x[v] / len
set BagSys__Camera_y[Output]=BagSys__Camera_y[v] / len
set BagSys__Camera_z[Output]=BagSys__Camera_z[v] / len
return Output
endfunction
function BagSys__Vec3Subtract takes integer Output,integer v1,integer v2 returns integer
set BagSys__Camera_x[Output]=BagSys__Camera_x[v1] - BagSys__Camera_x[v2]
set BagSys__Camera_y[Output]=BagSys__Camera_y[v1] - BagSys__Camera_y[v2]
set BagSys__Camera_z[Output]=BagSys__Camera_z[v1] - BagSys__Camera_z[v2]
return Output
endfunction
function BagSys__Vec3Cross takes integer Output,integer v1,integer v2 returns integer
set BagSys__Camera_x[Output]=BagSys__Camera_y[v1] * BagSys__Camera_z[v2] - BagSys__Camera_z[v1] * BagSys__Camera_y[v2]
set BagSys__Camera_y[Output]=BagSys__Camera_z[v1] * BagSys__Camera_x[v2] - BagSys__Camera_x[v1] * BagSys__Camera_z[v2]
set BagSys__Camera_z[Output]=BagSys__Camera_x[v1] * BagSys__Camera_y[v2] - BagSys__Camera_y[v1] * BagSys__Camera_x[v2]
return Output
endfunction
function BagSys__Vec3Transform_1 takes integer Output,integer v returns integer
local integer a=BagSys__VECTOR3_mat
local integer b=a + 1
local integer c=b + 1
set BagSys__Camera_x[Output]=BagSys__Camera_x[v] * BagSys__Camera_x[a] + BagSys__Camera_y[v] * BagSys__Camera_x + BagSys__Camera_z[v] * BagSys__Camera_x[c]
set BagSys__Camera_y[Output]=BagSys__Camera_x[v] * BagSys__Camera_y[a] + BagSys__Camera_y[v] * BagSys__Camera_y + BagSys__Camera_z[v] * BagSys__Camera_y[c]
set BagSys__Camera_z[Output]=BagSys__Camera_x[v] * BagSys__Camera_z[a] + BagSys__Camera_y[v] * BagSys__Camera_z + BagSys__Camera_z[v] * BagSys__Camera_z[c]
return Output
endfunction
function BagSys__Matrix3RotationAxis takes integer v,real a returns nothing
local real cosa=Cos(a)
local real sina=Sin(a)
local real cos_a=1 - cosa
local real x=BagSys__Camera_x[v]
local real y=BagSys__Camera_y[v]
local real z=BagSys__Camera_z[v]
local integer mat=BagSys__VECTOR3_mat
set BagSys__Camera_x[mat]=cosa + cos_a * x * x
set BagSys__Camera_y[mat]=cos_a * x * y - sina * z
set BagSys__Camera_z[mat]=cos_a * x * z + sina * y
set mat=mat + 1
set BagSys__Camera_x[mat]=cos_a * y * x + sina * z
set BagSys__Camera_y[mat]=cosa + cos_a * y * y
set BagSys__Camera_z[mat]=cos_a * y * z - sina * x
set mat=mat + 1
set BagSys__Camera_x[mat]=cos_a * z * x - sina * y
set BagSys__Camera_y[mat]=cos_a * z * y + sina * x
set BagSys__Camera_z[mat]=cosa + cos_a * z * z
endfunction
function BagSys__Camera_Win2World takes integer p,real X,real Y,real Range returns integer
local integer axisx=BagSys__Camera_AxisX[p]
local integer axisy=BagSys__Camera_AxisY[p]
local integer axisz=BagSys__Camera_AxisZ[p]
local integer eye=BagSys__Camera_Eye[p]
local integer Output=BagSys__Camera_Pos
set BagSys__Camera_x[Output]=BagSys__Camera_x[eye] + BagSys__Camera_x[axisz] * Range + X * BagSys__Camera_x[axisx] * BagSys__WidthScreen * Range + Y * BagSys__Camera_x[axisy] * BagSys__HeightScreen * Range
set BagSys__Camera_y[Output]=BagSys__Camera_y[eye] + BagSys__Camera_y[axisz] * Range + X * BagSys__Camera_y[axisx] * BagSys__WidthScreen * Range + Y * BagSys__Camera_y[axisy] * BagSys__HeightScreen * Range
set BagSys__Camera_z[Output]=BagSys__Camera_z[eye] + BagSys__Camera_z[axisz] * Range + X * BagSys__Camera_z[axisx] * BagSys__WidthScreen * Range + Y * BagSys__Camera_z[axisy] * BagSys__HeightScreen * Range
return Output
endfunction
function BagSys__Camera_UpdateAxisMatrix takes integer this,real ex,real ey,real ez,real tx,real ty,real tz returns nothing
local integer axisx=BagSys__Camera_AxisX[this]
local integer axisy=BagSys__Camera_AxisY[this]
local integer axisz=BagSys__Camera_AxisZ[this]
local integer eye=BagSys__Camera_Eye[this]
local integer at=BagSys__Camera_At[this]
set BagSys__Camera_x[at]=tx
set BagSys__Camera_y[at]=ty
set BagSys__Camera_z[at]=tz
set BagSys__Camera_x[eye]=ex
set BagSys__Camera_y[eye]=ey
set BagSys__Camera_z[eye]=ez
call BagSys__Vec3Normalize(axisz , BagSys__Vec3Subtract(axisz , at , eye))
call BagSys__Matrix3RotationAxis(axisz , - GetCameraField(CAMERA_FIELD_ROLL))
call BagSys__Vec3Normalize(axisx , BagSys__Vec3Cross(axisx , axisz , BagSys__VECTOR3_oneZ))
call BagSys__Vec3Transform_1(axisy , BagSys__Vec3Cross(axisy , axisx , axisz))
call BagSys__Vec3Transform_1(axisx , axisx)
endfunction
从这里往上看,就是每一段间隔更新下数据。
总的来说不是很复杂,不过让我自己来写我可写不出来,全是从链接里面的演示偷出来的。
function BagSys__CameraUpdate_ForPlayer takes integer p returns boolean
local real tx
local real ty
local real tz
local real X
local real Y
local real Z
local integer this
local integer at
local integer eye
if ( Lpid == p ) then
set X=GetCameraEyePositionX()
set Y=GetCameraEyePositionY()
set Z=GetCameraEyePositionZ()
set tx=GetCameraTargetPositionX()
set ty=GetCameraTargetPositionY()
set tz=GetCameraTargetPositionZ()
set this=BagSys__Camera_p[p]
set at=BagSys__Camera_At[this]
set eye=BagSys__Camera_Eye[this]
if ( ( not ( BagSys__Approximately(X , BagSys__Camera_x[eye] , 1) and BagSys__Approximately(Y , BagSys__Camera_y[eye] , 1) and BagSys__Approximately(Z , BagSys__Camera_z[eye] , 1) and BagSys__Approximately(tx , BagSys__Camera_x[at] , 1) and BagSys__Approximately(ty , BagSys__Camera_y[at] , 1) and BagSys__Approximately(tz , BagSys__Camera_z[at] , 1) ) ) ) then
call BagSys__Camera_UpdateAxisMatrix(this , X , Y , Z , tx , ty , tz)
return true
endif
endif
return false
endfunction
[/jass]
[jass]
这个函数就是用来摆放单位的位置的。
function BagSys__ButtonUpdate takes unit u,integer p returns nothing
local integer x=GetUnitUserData(u)
set x=BagSys__Camera_Win2World(BagSys__Camera_p[p] , BagSys__Button_centerx[x] , BagSys__Button_centery[x] , BagSys__ZSlot)
call SetUnitX(u, BagSys__Camera_x[x])
call SetUnitY(u, BagSys__Camera_y[x])
call SetUnitFlyHeight(u, BagSys__Camera_z[x] - BagSys__GetTerrainZ(BagSys__Camera_x[x] , BagSys__Camera_y[x]), 0)
endfunction
[/jass] |
|