• 🏆 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!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

[vJASS] xy angle of dummy.mdx?

Status
Not open for further replies.
Level 9
Joined
Jun 21, 2012
Messages
432
I work on dummy/projectile system similar to xe of vexorian...

My problem begins when i want to get or modify a angle of preload dummy, vexorian use this code to get it:

JASS:
private keyword xedummy
    private struct recycleQueue extends array
        recycleQueue next
        recycleQueue prev

        real angle

        integer size
        xedummy first
        xedummy last
        static method onInit takes nothing returns nothing
            local integer i=0
            loop
                exitwhen i==ANGLE_RESOLUTION
                set i=i+1
                set recycleQueue(i).prev=recycleQueue(i-1)
                set recycleQueue(i).next=recycleQueue(i+1)
                set recycleQueue(i).angle=(i-0.5)*(360.0/ANGLE_RESOLUTION)
            endloop
            set recycleQueue(1).prev=recycleQueue(i)
            set recycleQueue(i).next=recycleQueue(1)
        endmethod

        static method get takes real angle returns recycleQueue
            return recycleQueue(R2I(angle/360.0*ANGLE_RESOLUTION)+1)
        endmethod
    endstruct

// ================================================================

    struct xedummy
        private static group g=CreateGroup()
        private unit u

        // ----------------------------------------------------------------

        private xedummy next
        
        private method queueInsert takes recycleQueue q returns nothing
            call SetUnitFacing(.u, q.angle)

            if q.size==0 then
                set q.first=this
            else
                set q.last.next=this
            endif
            set q.last=this
            set .next=0

            // Recursively check adajcent queues and migrate xedummies as needed.
            if q.size>q.next.size then
                set this=q.first
                set q.first=.next
                call .queueInsert(q.next)
            elseif q.size>q.prev.size then
                set this=q.first
                set q.first=.next
                call .queueInsert(q.prev)
            else
                set q.size=q.size+1
            endif
        endmethod
        
        private static method queueRemove takes recycleQueue q returns xedummy
            // Recursively check adajcent queues and migrate xedummies as needed.
            local xedummy this
            if q.size<q.next.size then
                set this=q.last
                set q.last=.queueRemove(q.next)
                set .next=q.last
                call SetUnitFacing(q.last.u, q.angle)
            elseif q.size<q.prev.size then
                set this=q.last
                set q.last=.queueRemove(q.prev)
                set .next=q.last
                call SetUnitFacing(q.last.u, q.angle)
            else
                set q.size=q.size-1
                if q.size==0 then
                    set q.last=0
                endif
            endif

            set this=q.first
            set q.first=.next
            set .next=0
            return this
        endmethod

The angle z is got by dummy.mdx animations, now my question is: would be possible to get the xy angle with appropriate animations?
 
The undoubtedly best way of setting a dummy units orientation is using SetUnitLookAt, with the orientation vector as the offset. Here's an example:

JASS:
call SetUnitLookAt(.u, "Bone_Head", .u, .xv*100000, .yv*100000, .zv*100000)

In the above case, "u" is the dummy, while xv, yv and zv are the velocity vectors. This will make the unit face the direction of the veolcity, and is much more reliable than SetUnitFacing, which can be irresponsive at times.

Now, there are a few perks/drawbacks to this. Firstly, the bounds of the dummy model must overlap the map center. This is an easy fix. Second, you need to set the units position using SetUnitPosition afterwards - SetUnitX/Y will not work (the unit will move, but the orientation will not update). Also note that this method assumes that "Bone_Head" is the name of the root bone of the model (only "Bone_Head" and "Bone_Chest" are supported by the function). I am using a dummy which instead of having pitch angles animated, has roll angles. This way, you can also set the roll, and thus manipulate the rotation in all three dimensions. The other, more obvious perk is that you do not need to calculate any expensive Atan or Cos values to set the orientation (other than when calculating the orientation vector).

Let me know if you want to try the roll dummy i am using, and i can send it to you. I also recommend you checking out Bob666's FlightSim, where he uses it together with a custom quaternion library (awesome) to handle rotations without the risk of gimbal lock. Overall, using a vector and quaternion based approach to a missile system makes things a LOT easier and more readable for you. Quaternion math is a bit special, but if you haven't worked with them before, i can teach you in 10 minutes if you need to.
 
Level 9
Joined
Jun 21, 2012
Messages
432
Thanks for the explanation! ok send me your dummy for a look :ogre_hurrhurr:

Edit1: I'm reviewing FlightSim, looks good

Edit2: this is much better than using dummy.mdx with animations, I enjoy: D .... FlightSim reminds me when I was playing Gta san andreas xd

Edit3: now I will review the code of this map but however I hope you send me your dummy system.
 
Status
Not open for further replies.
Top