(Keeps Hive Alive)
Go Back   The Hive Workshop - A Warcraft III Modding Site > Warcraft III Hosted Projects > Reinventing the Craft > Tutorials

Tutorials This forum contains tutorials on current custom natives.

Closed Thread
 
LinkBack Thread Tools Display Modes
Old 12-10-2007, 07:39 PM   #1 (permalink)
 
MindWorX's Avatar

Wulfy loves Nex!
 
Join Date: Aug 2004
Posts: 293

MindWorX has a spectacular aura about (122)MindWorX has a spectacular aura about (122)MindWorX has a spectacular aura about (122)MindWorX has a spectacular aura about (122)

PayPal Donor: This user has donated to The Hive. Hosted Project of the Year 2007: Reinventing the Craft 

AdvancedCameraControl Example

library AdvancedCameraControl initializer Init
    globals
        //Settings
        private real real_ZoomMinDistance = 0.00 //Min Zoom Distance
        private real real_ZoomMaxDistance = 3000.00 //Max Zoom Distance
        private real real_ZoomDistance = 1700.00 //Initial Zoom Distance
        private real real_ZoomDistanceChange = 256.00 //Step per wheel scroll step
        private real real_AoA = 304.00 //Initial Angle
        private real real_Rot = 90.00 //Initial Direction

        //System
        private constant trigger trig_OnMouseLeftDown = CreateTrigger()
        private constant trigger trig_OnMouseLeftUp = CreateTrigger()
        private constant trigger trig_OnMouseRightDown = CreateTrigger()
        private constant trigger trig_OnMouseRightUp = CreateTrigger()
        private boolean bool_MouseLeftState = false
        private boolean bool_MouseRightState = false

        private constant trigger trig_OnMouseWheel = CreateTrigger()
        private constant trigger trig_AoAControl = CreateTrigger()
        private boolean bool_AoAChanging = false
        private integer int_AoAOffsetY = GetMouseY()
        private integer int_AoAOffsetX = GetMouseX()
    endglobals

        //=== Set Left Mouse Button Down State
    private function OnMouseLeftDown takes nothing returns nothing
        set bool_MouseLeftState = true
    endfunction

        //=== Set Left Mouse Button Up State
    private function OnMouseLeftUp takes nothing returns nothing
        set bool_MouseLeftState = false
        set bool_AoAChanging = false
    endfunction

        //=== Set Right Mouse Button Down State
    private function OnMouseRightDown takes nothing returns nothing
        set bool_MouseRightState = true
endfunction

        //=== Set Right Mouse Button Up State
    private function OnMouseRightUp takes nothing returns nothing
        set bool_MouseRightState = false
        set bool_AoAChanging = false
    endfunction

    function GetMouseLeftState takes nothing returns boolean
        return bool_MouseLeftState
    endfunction

    function GetMouseRightState takes nothing returns boolean
        return bool_MouseRightState
    endfunction

    private function AoAControl takes nothing returns nothing
     local boolean b = GetMouseRightState() and GetMouseLeftState()
        if(b) then
            set bool_AoAChanging = true
            set int_AoAOffsetY = GetMouseY()
            set int_AoAOffsetX = GetMouseX()
        endif
    endfunction

        //=== Zooming
private function OnMouseWheel takes nothing returns nothing
     local integer WheelDelta = GetTriggerWheelDelta()
     local real zoomchange = real_ZoomDistanceChange * (ISignBJ(WheelDelta) * -1)
        set real_ZoomDistance = real_ZoomDistance + zoomchange
        if(real_ZoomDistance < real_ZoomMinDistance) then
            set real_ZoomDistance = real_ZoomMinDistance
        endif
        if(real_ZoomDistance > real_ZoomMaxDistance) then
            set real_ZoomDistance = real_ZoomMaxDistance
        endif
    endfunction

    function CameraControl takes nothing returns nothing
     local real offset = 0
        call SetCameraField(CAMERA_FIELD_TARGET_DISTANCE, real_ZoomDistance, 1.00)
        if(bool_AoAChanging) then
            set offset = (int_AoAOffsetY - GetMouseY())
            set real_AoA = real_AoA + offset
            set int_AoAOffsetY = GetMouseY()
        endif
        if(real_AoA > 350) then
            set real_AoA = 350
        endif
        if(real_AoA < 270) then
            set real_AoA = 270
        endif
        call SetCameraField(CAMERA_FIELD_ANGLE_OF_ATTACK, real_AoA, 0.00)
        if(bool_AoAChanging) then
            set offset = (int_AoAOffsetX - GetMouseX())
            set real_Rot = real_Rot + offset
            set int_AoAOffsetX = GetMouseX()
        endif
        if(real_Rot > 360) then
            set real_Rot = real_Rot - 360
        endif
        if(real_Rot < 0) then
            set real_Rot = real_Rot + 360
        endif
        call SetCameraField(CAMERA_FIELD_ROTATION, real_Rot, 0.00)
    endfunction

    private function Init takes nothing returns nothing
     local trigger t = CreateTrigger()

        call TriggerRegisterTimerEvent(t, 0.01, true)
        call TriggerAddAction(t, function CameraControl)

        call TriggerRegisterMouseEvent(trig_OnMouseLeftDown, EVENT_LMOUSEDOWN)
        call TriggerAddAction(trig_OnMouseLeftDown, function OnMouseLeftDown)

        call TriggerRegisterMouseEvent(trig_OnMouseLeftUp, EVENT_LMOUSEUP)
        call TriggerAddAction(trig_OnMouseLeftUp, function OnMouseLeftUp)

        call TriggerRegisterMouseEvent(trig_OnMouseRightDown, EVENT_RMOUSEDOWN)
        call TriggerAddAction(trig_OnMouseRightDown, function OnMouseRightDown)

        call TriggerRegisterMouseEvent(trig_OnMouseRightUp, EVENT_RMOUSEUP)
        call TriggerAddAction(trig_OnMouseRightUp, function OnMouseRightUp)

        call TriggerRegisterMouseEvent(trig_OnMouseWheel, EVENT_MOUSEWHEEL)
        call TriggerAddAction(trig_OnMouseWheel, function OnMouseWheel)

        call TriggerRegisterMouseEvent(trig_AoAControl, EVENT_LMOUSEDOWN)
        call TriggerRegisterMouseEvent(trig_AoAControl, EVENT_RMOUSEDOWN)
        call TriggerAddAction(trig_AoAControl, function AoAControl)
    endfunction
endlibrary

Uncommented atm, but it's pretty straight forward. It uses a vJass library setup, so it requires NewGen to be used in a map.

It gives more control of the camera, allowing you to move the angle of attack and direction by holding down both the left and right mouse button, and allows much better zoom.
__________________
"Wulfy loves Nex!"

Last edited by MindWorX; 12-10-2007 at 09:40 PM..
MindWorX is offline  
Closed Thread

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump

All times are GMT. The time now is 09:31 AM.






Your link here 
Online Loans | Secured Credit Cards | Debt Consolidation | Internet Advertising | Advertising
Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
Copyright©Ralle