• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

Camera Angle of Attack

Status
Not open for further replies.
Level 9
Joined
Oct 5, 2008
Messages
81
Hello all. Please.
How to make dynamic Angle of Attack of Camera for a unit moving on steep mountains or lower ground?
I've done rotation of unit and height offset but i need this one for complete dynamic camera.
And would be good if it could be done in GUI.
Here is example picture.
 

Attachments

  • AOA CAM.jpg
    AOA CAM.jpg
    83.4 KB · Views: 687
Level 18
Joined
Jan 21, 2006
Messages
2,552
Well actually at the top of the hill you don't want to be able to seem straight, you want to be able to see down the mountain, mainly the ground on either side of you (meaning the camera will have to be more above the unit). Anyways, I've done some work on a camera system like this, what I have so far is in vJass but you are welcome to use it, and I would be more than happy to help you implement it.

JASS:
library Camera

//##############################################################################################
globals
//**********************************************************************************************  
// Configuration Constants
// ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯ 
//  Default constant values used for initializing each static camera instance.
//
    public      constant real       DEFAULT_PAN_DURATION        = 0.55
//
//  The following configuration constants are preferred defaults. The camera is set
//  to perform best under these circumstances, though adjustments *can* be made if it
//  is necessary.
//
    public      constant real       DEFAULT_TARGET_DISTANCE     = 1000
    public      constant real       DEFAULT_ZOFFSET             = 30
    public      constant real       DEFAULT_ANGLE_OF_ATTACK     = 340
//
//
//**********************************************************************************************
endglobals

globals
//**********************************************************************************************
// Dynamic Storage Utility
// ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
// These are private storage variables that allow easy-access of utilities, such as
// the GetLocationZ function which allows terrain-detection.
    private     constant location   core__tempLoc           = Location(0, 0)
    private     real                core__tempLocZ          
//
//
//**********************************************************************************************    
endglobals

//##############################################################################################
private struct cameradata
    public          real            targetDistance
    public          real            angleOfAttack
    public          real            zOffset
    
    static method create takes nothing returns thistype
        local thistype data=allocate()
        set data.targetDistance=DEFAULT_TARGET_DISTANCE
        set data.angleOfAttack=DEFAULT_ANGLE_OF_ATTACK
        set data.zOffset=DEFAULT_ZOFFSET
        return data
    endmethod
endstruct

//##############################################################################################
struct camera extends array

    private         unit            cam__controller
    private         cameradata      cam__specData
    readonly        player          controllerPlayer
    
    private         boolean         cam__enabled       
    
    public          boolean         inheritRotation
    public          real            panDuration         
    
    readonly        boolean         isLocal
    readonly static thistype        localCamera
    
    private static  timer           core__looptmr       = CreateTimer()
    private static  constant real   core__looptmrRef    = 0.04
    
    
    
    method operator controller takes nothing returns unit
        return cam__controller
    endmethod
    method operator controller= takes unit u returns nothing
        set cam__controller=u
        if(isLocal) then
            call SetCameraTargetController(cam__controller, 0, 0, true)
        endif
    endmethod

    
    method start takes boolean rotation returns boolean  
        set inheritRotation = rotation
        //If there is an available camera-target then .start() will return true. If no target is
        //available at all then "inheritRotation" will be queued for when .controller= is used
        return cam__controller != null
    endmethod
    method stop takes nothing returns nothing
        set inheritRotation = false
        if (isLocal) then
            call StopCamera()
            
        endif
    endmethod
    
    
    static if(DEBUG_MODE) then
        //The following code will only be implemented if DEBUG_MODE is enabled.
        private static method debug takes nothing returns nothing
            
        endmethod
    endif
    
    
    private static method loopFunc takes nothing returns nothing
        local real r0=SquareRoot(Pow(GetCameraEyePositionX(), 2)+Pow(GetCameraEyePositionY(), 2))
        local real r1=SquareRoot(Pow(GetCameraTargetPositionX(), 2)+Pow(GetCameraTargetPositionY(), 2))
        local real d =GetCameraTargetPositionZ()-GetCameraEyePositionZ()
        set d=SquareRoot((r1-r0)*(r1-r0)+(d*d))
    
        call MoveLocation(core__tempLoc, GetUnitX(localCamera.controller), GetUnitY(localCamera.controller))
        set core__tempLocZ=GetLocationZ(core__tempLoc)
        
        if(localCamera.isLocal) then
            if(localCamera.inheritRotation) then
                call SetCameraField(CAMERA_FIELD_ROTATION, GetUnitFacing(localCamera.controller),/*
                                                                            */localCamera.panDuration)
            endif
            //In order to counter-weight the smoothing that the camera uses we must find out the
            //offset and correct it using ZOFFSET. On flat-ground, diffz will be 0.00.
            call SetCameraField(CAMERA_FIELD_ZOFFSET, core__tempLocZ-GetCameraTargetPositionZ()/*
                                            */+localCamera.cam__specData.zOffset+(GetCameraEyePositionZ()/*
                                            */-core__tempLocZ)/5, localCamera.panDuration)
            
            //Now we must adjust the target-distance depending on how much the result has varied from it's original
            set core__tempLocZ=localCamera.cam__specData.targetDistance-d
            
            call SetCameraField(CAMERA_FIELD_TARGET_DISTANCE,/*
                                            */localCamera.cam__specData.targetDistance+(core__tempLocZ/3),/*
                                            */localCamera.panDuration)
            call SetCameraField(CAMERA_FIELD_ANGLE_OF_ATTACK,/*
                                            */localCamera.cam__specData.angleOfAttack-(GetCameraField(CAMERA_FIELD_ZOFFSET)/6),/*
                                            */localCamera.panDuration)
        endif
        
        debug call debug()
    endmethod

    
    //==========================================================================================
    private static method onInit takes nothing returns nothing
        local integer i = 0
        loop
            exitwhen(i == 12)
            
            //Initialize camera components:
            set camera[i].controllerPlayer  =Player(i)
            set camera[i].cam__controller   =null
            set camera[i].cam__specData     =cameradata.create()
            set camera[i].panDuration       =DEFAULT_PAN_DURATION
            
            //Setup local camera data:
            set camera[i].isLocal           =false
            
            set i = i + 1
        endloop
        //Finalize local data:
        set localCamera         = camera[GetPlayerId(GetLocalPlayer())]
        set localCamera.isLocal = true
        //Initialize update/refresh loop timer:
        call TimerStart(core__looptmr, core__looptmrRef, true, function thistype.loopFunc)
    endmethod
    
    
endstruct


endlibrary

When this library is copied into your map script, it will automatically adjust the angle of attack and a few other camera fields to make it run smoothly across varying terrain. It is fairly easy to use, too, though you have to at least have JNGP.

Link: http://www.hiveworkshop.com/forums/triggers-scripts-269/3rd-person-camera-168781/

That is the original post that I started about this topic. I couldn't find it by searching "camera" but it showed up right away when I specified my name in the advanced search. I hope this helps.
 
Status
Not open for further replies.
Top