Camera help

For fulfilled maps that most likely don't work on the latest patch (1.24 or later).

Moderator: Cheaters

ProWorks
Newcomer
Posts: 6
Joined: April 10th, 2009, 6:31 pm

Camera help

Post by ProWorks »

Can someone please make a camera sytem like eclipse orpg has in gui....
It follows the hero, looks where he looks and is low height
Heres eclipse orpg deprotected with singleplayer if you need to look http://rapidshare.com/files/234080767/E ... _.w3x.html (Credits go to Risen for deprtecting the map)
you'll get credits in my orpg :D ty
Image

Image
User avatar
Risen
Forum Staff
Posts: 811
Joined: January 1st, 2008, 12:58 am

Re: Camera help

Post by Risen »

It's kinda hard to just 'grab' Eclipse's camera system out of it's map.

There's many buggy ones.. I can get you mine, but it's vJass.

- Dynamic Camera -
Spoiler:

Code: Select all

library DynamicCamera initializer Init

globals
    location CamLoc=Location(0,0)
    
    //Use the x values as the angle of attack values. Y values are the according distance/offset values.
    //Example:
    //DISTANCEX1 = 345
    //DISTANCEY1 = 300
    //DISTANCEX2 = 295
    //DISTANCEY2 = 600
    //This means you want the camera distance to be 300 at an angle of 345 and 600 at an angle of 295.
    //The values inbetween will be calculated automatically.
    //ZOFFSET is the basic camera offset:
    constant real DISTANCEX1 = 345
    constant real DISTANCEY1 = 300
    constant real DISTANCEX2 = 295
    constant real DISTANCEY2 = 600
    constant real OFFSETX1 = 345
    constant real OFFSETY1 = 0
    constant real OFFSETX2 = 295
    constant real OFFSETY2 = 200
    constant real ZOFFSET = 100
    
    //These are intern values for the dynamic functions GetDynamicDistance and GetDynamicOffset:
    real DistanceM
    real DistanceT
    real OffsetM
    real OffsetT
    
    //Gloabs used in the example usage
    unit array Hero
    boolean array Key_Up
    boolean array Key_Down
    boolean array Key_Right
    boolean array Key_Left
    boolean array Locked
    boolean array Rotate
    real array ControlableAoA
    real array ControlableRot
endglobals

//private function GetFunctionM takes real x1, real y1, real x2, real y2 returns real
//    return (y2-y1)/(x2-x1)
//endfunction
//private function GetFunctionT takes real x1, real y1, real x2, real y2 returns real
//    return y1-x1*GetFunctionM(x1, y1, x2, y2)
//endfunction

//You can replace this function if you already have a similar one in your map
private function ProjectX takes real x, real inc, real a returns real
    return x+inc*Cos(a*bj_DEGTORAD)
endfunction

//You can replace this function if you already have a similar one in your map
private function ProjectY takes real y, real inc, real a returns real
    return y+inc*Sin(a*bj_DEGTORAD)
endfunction

//You can replace this function if you already have a similar one in your map
private function DistanceBetweenXY takes real x1, real y1, real x2, real y2 returns real
    return SquareRoot((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1))
endfunction

//Dynamic functions for distance and offset. Basically these are linear mathematical functions y = mx+t
private function GetDynamicDistance takes real angleOfAttack returns real
    return DistanceM*angleOfAttack+DistanceT
endfunction

private function GetDynamicOffset takes real angleOfAttack returns real
    return OffsetM*angleOfAttack+OffsetT
endfunction

//Camera actions, lots of stuff. All working :)
function UseDynamicCam takes unit whichUnit, boolean locked, boolean rotate returns nothing
    local integer p=GetPlayerId(GetLocalPlayer())
    local real unitx=GetUnitX(whichUnit)
    local real unity=GetUnitY(whichUnit)
    local real camx=GetCameraEyePositionX()
    local real camy=GetCameraEyePositionY()
    local real camz
    local real camrot=GetCameraField(CAMERA_FIELD_ROTATION)
    local real camzoff=GetCameraField(CAMERA_FIELD_ZOFFSET)
    local real angleofattack=GetCameraField(CAMERA_FIELD_ANGLE_OF_ATTACK)*bj_RADTODEG 
    local real offsetx=camx+350*Cos(camrot+bj_PI)
    local real offsety=camy+350*Sin(camrot+bj_PI)
    local real offsetz
    local real unitangle=GetUnitFacing(whichUnit)
    local real panx=ProjectX(unitx, GetDynamicOffset(angleofattack), unitangle)
    local real pany=ProjectY(unity, GetDynamicOffset(angleofattack), unitangle)
    local real anticlipangle
    local real distance
    
    if angleofattack>345 then
        set panx=unitx
        set pany=unity
    endif
    
    if locked then
        call PanCameraToTimed(panx, pany, 0.5)
    endif
    if rotate then
        call SetCameraField(CAMERA_FIELD_ROTATION, unitangle+ControlableRot[p], 0.75)
    endif
    
    call MoveLocation(CamLoc, camx, camy)
    set camz=GetLocationZ(CamLoc)+GetUnitFlyHeight(whichUnit)
    call MoveLocation(CamLoc, offsetx, offsety)
    set offsetz=GetLocationZ(CamLoc)
    
    set distance=DistanceBetweenXY(panx, pany, camx, camy)
    
    set anticlipangle=357-bj_RADTODEG*Atan((offsetz-camz-camzoff)/distance)

    if ControlableAoA[p]>anticlipangle then
        call SetCameraField(CAMERA_FIELD_ANGLE_OF_ATTACK, anticlipangle, 0.5)
    else
        call SetCameraField(CAMERA_FIELD_ANGLE_OF_ATTACK, ControlableAoA[p], 0.5)
    endif
    call SetCameraField(CAMERA_FIELD_TARGET_DISTANCE, GetDynamicDistance(angleofattack), 0.5)
    call SetCameraField(CAMERA_FIELD_ZOFFSET, camzoff-GetCameraTargetPositionZ()+camz+ZOFFSET, 0.5)
    call SetCameraField(CAMERA_FIELD_FIELD_OF_VIEW, 120, 0)
endfunction

//===========================================================================
private function Init takes nothing returns nothing
    local integer i=0
    set DistanceM=(DISTANCEY2-DISTANCEY1)/(DISTANCEX2-DISTANCEX1)
    set DistanceT=DISTANCEY1-DISTANCEX1*DistanceM
    set OffsetM=(OFFSETY2-OFFSETY1)/(OFFSETX2-OFFSETX1)
    set OffsetT=OFFSETY1-OFFSETX1*OffsetM
    
    //set DistanceM=GetFunctionM(DISTANCEX1, DISTANCEY1, DISTANCEX2, DISTANCEY2)
    //set DistanceT=GetFunctionT(DISTANCEX1, DISTANCEY1, DISTANCEX2, DISTANCEY2)
    //set OffsetM=GetFunctionM(OFFSETX1, OFFSETY1, OFFSETX2, OFFSETY2)
    //set OffsetT=GetFunctionT(OFFSETX1, OFFSETY1, OFFSETX2, OFFSETY2)
    
    //This sets the defult values for the variables
    loop
      exitwhen i==12 //Change this to the max number of human controled players
        set ControlableAoA[i]=340
        set ControlableRot[i]=0
        set Locked[i]=true
        set Rotate[i]=true
        set Hero[i]=CreateUnit(Player(i), 'hrif', GetRandomReal(-1000, 1000), GetRandomReal(-1000, 1000), GetRandomReal(0, 360))
        set i=i+1
    endloop
endfunction

endlibrary
- Camera Commands -
Spoiler:

Code: Select all

function LockActions takes nothing returns nothing
    set Locked[GetPlayerId(GetTriggerPlayer())]=true
endfunction

function TriggerRegisterAnyPlayerEvent takes trigger trig, playerevent pvent returns nothing
    local integer i=0
    loop
      exitwhen i==16
        call TriggerRegisterPlayerEvent(trig, Player(i), pvent)
        set i=i+1
    endloop
endfunction

function TriggerRegisterAnyPlayerChatEvent takes trigger trig, string text, boolean match returns nothing 
    local integer i=0
    loop
      exitwhen i==12
        call TriggerRegisterPlayerChatEvent(trig, Player(i), text, match)
        set i=i+1
    endloop
endfunction

function UnlockActions takes nothing returns nothing
    set Locked[GetPlayerId(GetTriggerPlayer())]=false
endfunction

function RotateActions takes nothing returns nothing
    local integer p=GetPlayerId(GetTriggerPlayer())
    if Rotate[p] then
        set Rotate[p]=false
    else
        set Rotate[p]=true
    endif
endfunction

function ResetActions takes nothing returns nothing
    local integer p=GetPlayerId(GetTriggerPlayer())
    set ControlableAoA[p]=340
    set ControlableRot[p]=0
    if GetLocalPlayer()==Player(p) then
        call UseDynamicCam(Hero[p], Locked[p], Rotate[p])
    endif
endfunction

//===========================================================================
function InitTrig_CameraCommands takes nothing returns nothing
    set gg_trg_CameraCommands=CreateTrigger()
    call TriggerRegisterAnyPlayerChatEvent(gg_trg_CameraCommands, "-lock", true)
    call TriggerAddAction(gg_trg_CameraCommands, function LockActions)
    
    set gg_trg_CameraCommands=CreateTrigger()
    call TriggerRegisterAnyPlayerChatEvent(gg_trg_CameraCommands, "-unlock", true)
    call TriggerAddAction(gg_trg_CameraCommands, function UnlockActions)
    
    set gg_trg_CameraCommands=CreateTrigger()
    call TriggerRegisterAnyPlayerChatEvent(gg_trg_CameraCommands, "-rotate", true)
    call TriggerAddAction(gg_trg_CameraCommands, function RotateActions)
    
    set gg_trg_CameraCommands=CreateTrigger()
    call TriggerRegisterAnyPlayerChatEvent(gg_trg_CameraCommands, "-reset", true)
    call TriggerAddAction(gg_trg_CameraCommands, function ResetActions)
endfunction
- Camera Periodic -
Spoiler:

Code: Select all

function CameraPeriodicActions takes nothing returns boolean
    local integer i=0
    loop
        exitwhen i==12
        if GetPlayerSlotState(Player(i))==PLAYER_SLOT_STATE_PLAYING then
            if Key_Up[i]==true and ControlableAoA[i]>295 then
                set ControlableAoA[i]=ControlableAoA[i]-1.5
            endif
            if Key_Down[i]==true and ControlableAoA[i]<355 then
                set ControlableAoA[i]=ControlableAoA[i]+1.5
            endif
            if Key_Left[i]==true and ControlableRot[i]>-105 then
                set ControlableRot[i]=ControlableRot[i]-7.5
            endif
            if Key_Right[i]==true and ControlableRot[i]<105 then
                set ControlableRot[i]=ControlableRot[i]+7.5
            endif
            if GetLocalPlayer()==Player(i) then
                call UseDynamicCam(Hero[i], Locked[i], Rotate[i])
            endif
        endif
        set i=i+1
    endloop
    return false
endfunction

//===========================================================================
function InitTrig_CameraPeriodic takes nothing returns nothing
    set gg_trg_CameraPeriodic=CreateTrigger()
    call TriggerRegisterTimerEvent(gg_trg_CameraPeriodic, 0.1, true)
    call TriggerAddCondition(gg_trg_CameraPeriodic, Condition(function CameraPeriodicActions))
endfunction
- Camera Keys -
Spoiler:

Code: Select all

function UPActions takes nothing returns nothing
    local integer i=GetPlayerId(GetTriggerPlayer())
    set Key_Up[i]=true
    if ControlableAoA[i]>295 then
        set ControlableAoA[i]=ControlableAoA[i]-1.5
    endif
endfunction
function URActions takes nothing returns nothing
    set Key_Up[GetPlayerId(GetTriggerPlayer())]=false
endfunction

function DPActions takes nothing returns nothing
    local integer i=GetPlayerId(GetTriggerPlayer())
    set Key_Down[i]=true
    if ControlableAoA[i]<355 then
        set ControlableAoA[i]=ControlableAoA[i]+1.5
    endif
endfunction
function DRActions takes nothing returns nothing
    set Key_Down[GetPlayerId(GetTriggerPlayer())]=false
endfunction

function RPActions takes nothing returns nothing
    local integer i=GetPlayerId(GetTriggerPlayer())
    set Key_Right[i]=true
    if ControlableRot[i]<105 then
        set ControlableRot[i]=ControlableRot[i]+7.5
    endif
endfunction
function RRActions takes nothing returns nothing
    set Key_Right[GetPlayerId(GetTriggerPlayer())]=false
endfunction

function LPActions takes nothing returns nothing
    local integer i=GetPlayerId(GetTriggerPlayer())
    set Key_Left[i]=true
    if ControlableRot[i]>-105 then
        set ControlableRot[i]=ControlableRot[i]-7.5
    endif
endfunction
function LRActions takes nothing returns nothing
    set Key_Left[GetPlayerId(GetTriggerPlayer())]=false
endfunction

//===========================================================================
function InitTrig_CameraKeys takes nothing returns nothing
    set gg_trg_CameraKeys=CreateTrigger()
    call TriggerRegisterAnyPlayerEvent(gg_trg_CameraKeys, EVENT_PLAYER_ARROW_UP_DOWN)
    call TriggerAddAction(gg_trg_CameraKeys, function UPActions)
    set gg_trg_CameraKeys=CreateTrigger()
    call TriggerRegisterAnyPlayerEvent(gg_trg_CameraKeys, EVENT_PLAYER_ARROW_UP_UP)
    call TriggerAddAction(gg_trg_CameraKeys, function URActions)
    
    set gg_trg_CameraKeys=CreateTrigger()
    call TriggerRegisterAnyPlayerEvent(gg_trg_CameraKeys, EVENT_PLAYER_ARROW_DOWN_DOWN)
    call TriggerAddAction(gg_trg_CameraKeys, function DPActions)
    set gg_trg_CameraKeys=CreateTrigger()
    call TriggerRegisterAnyPlayerEvent(gg_trg_CameraKeys, EVENT_PLAYER_ARROW_DOWN_UP)
    call TriggerAddAction(gg_trg_CameraKeys, function DRActions)
    
    set gg_trg_CameraKeys=CreateTrigger()
    call TriggerRegisterAnyPlayerEvent(gg_trg_CameraKeys, EVENT_PLAYER_ARROW_RIGHT_DOWN)
    call TriggerAddAction(gg_trg_CameraKeys, function RPActions)
    set gg_trg_CameraKeys=CreateTrigger()
    call TriggerRegisterAnyPlayerEvent(gg_trg_CameraKeys, EVENT_PLAYER_ARROW_RIGHT_UP)
    call TriggerAddAction(gg_trg_CameraKeys, function RRActions)
    
    set gg_trg_CameraKeys=CreateTrigger()
    call TriggerRegisterAnyPlayerEvent(gg_trg_CameraKeys, EVENT_PLAYER_ARROW_LEFT_DOWN)
    call TriggerAddAction(gg_trg_CameraKeys, function LPActions)
    set gg_trg_CameraKeys=CreateTrigger()
    call TriggerRegisterAnyPlayerEvent(gg_trg_CameraKeys, EVENT_PLAYER_ARROW_LEFT_UP)
    call TriggerAddAction(gg_trg_CameraKeys, function LRActions)
endfunction
Image
Wanna learn to hack maps? --> Guide
ProWorks
Newcomer
Posts: 6
Joined: April 10th, 2009, 6:31 pm

Re: Camera help

Post by ProWorks »

Ty might work but can you tell me how to put this is my map....? I'd really appreciate it :)
Image

Image
User avatar
Risen
Forum Staff
Posts: 811
Joined: January 1st, 2008, 12:58 am

Re: Camera help

Post by Risen »

Whatever the spoiler is named, E.G: "Dynamic Camera", Just name a trigger as that and copy + paste all of the functions into the new trigger.

A real C++ 'God' wouldn't have any trouble doing this.. hell, he'd make his own very efficient vJass Cam system right on the spot.
Image
Wanna learn to hack maps? --> Guide
ProWorks
Newcomer
Posts: 6
Joined: April 10th, 2009, 6:31 pm

Re: Camera help

Post by ProWorks »

jass is a lil dif than C++ lols and diff template anyway i can understand alot of the jass coding I'd like to try but i cant figure out how to get rid of the conditions and stuff Events Conditions and Actions that it auto has when i make a new trigger....Nvm i played with it a bit and i found out how i meant before i couldnt find convert to custom text button......
Image

Image
User avatar
Risen
Forum Staff
Posts: 811
Joined: January 1st, 2008, 12:58 am

Re: Camera help

Post by Risen »

Yeah, Jass is totally different.. Syntax wise.

Basically you just need to know the order things run, and how they run, and you're good.
Image
Wanna learn to hack maps? --> Guide
ProWorks
Newcomer
Posts: 6
Joined: April 10th, 2009, 6:31 pm

Re: Camera help

Post by ProWorks »

,.......I still cant get it working tons of compile errors can you post and example map with this camera system in it that works?
*Edit made a cam system myself.....
Image

Image