Coordinate problem

Reaction score
456
For me, with zenith of 0, I can't even see the rock, and soon, wc3 crashes.

@BuilderBob
I fixed that problem by reducing 180 degrees from the angle:
set angle = Atan2(p2.y - p1.y, p2.x - p1.x) + zAngle - (180.00 * bj_DEGTORAD)
 
Reaction score
456
The current problem is to make the function to be able to turn point around any axis. :)
 

SerraAvenger

Cuz I can
Reaction score
234
done : )
There was just one thing I did not see: the zenith will change its direction after getting the maximum or minimum height. I have changed the function to return the new zenith, so that it will automatically change its sign according to the direction. Note that you can change the function to return just -1 or 1 in order to get a similiar effect with changing zeniths.
Demo map included, to show you how to use this code.

Code:
struct point
    real x
    real y
    real z
    static method create takes real x, real y, real z returns point
        local point new = point.allocate()
        
            set new.x = x
            set new.y = y
            set new.z = z 
 
        return new
    endmethod
            
    method rotate takes point fixpoint, real zenith, real azimuth returns real
        local real deltaX = .x - fixpoint.x
        local real deltaY = .y - fixpoint.y
        local real deltaZ = .z - fixpoint.z
        local real euclideanDist = SquareRoot( deltaX * deltaX + deltaY * deltaY + deltaZ * deltaZ )
        local real d2Distance    = SquareRoot( deltaX * deltaX + deltaY * deltaY )
        local real newZenith
        local real newAzimuth
       
        // new Zenith    
        set newZenith = Atan2( d2Distance, deltaZ ) + zenith * bj_DEGTORAD

        // new Azimuth
        if deltaX == 0 and deltaY == 0 then        
            set newAzimuth = 0             
        else
            set newAzimuth = Atan2( deltaY , deltaX ) + azimuth * bj_DEGTORAD
        endif
       
        set .x   = fixpoint.x + euclideanDist * Sin( newZenith ) * Cos( newAzimuth )
        set .y   = fixpoint.y + euclideanDist * Sin( newZenith ) * Sin( newAzimuth )
        set .z   = fixpoint.z + euclideanDist * Cos( newZenith )
        
        if newZenith > bj_PI or newZenith < 0 then
            return -zenith
        else
            return zenith
        endif
        
    endmethod

endstruct
 

Attachments

  • PointTester.w3x
    27.4 KB · Views: 208
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top