Finished the next updates...
haven't tested x,y,z setters (all) or x,y,z (position type) getters with PositionOrigin enabled, but everything else has been tested =P.
It's kinda cool... was moving a peasant around and 2 units were tied to it o-o.
JASS:
struct tests extends array
private static method onInit takes nothing returns nothing
local Position p = Position[CreateUnit(Player(0), 'hpea', WorldBounds.centerX, WorldBounds.centerY, 270)]
local Position p3 = Position[CreateUnit(Player(0), 'hfoo', WorldBounds.centerX, WorldBounds.centerY, 180)]
local Position p4 = Position[CreateUnit(Player(0), 'hrif', WorldBounds.centerX, WorldBounds.centerY, 0)]
set p.z = 300
set p3.z = 450
set p4.z = 150
set p3.x = WorldBounds.centerX
set p3.y = WorldBounds.centerY+300
set p4.x = WorldBounds.centerX
set p4.y = WorldBounds.centerY-300
call p.lock()
call p3.lock()
set p3.origin = p
set p3.locked = true
call p4.lock()
set p4.origin = p
set p4.locked = true
set p3.relative = true
set p4.relative = true
endmethod
endstruct
Let's see, it maintained facing, x, y, and z position relative to the origin's facing, x, y, and z position. So yea... if a footmen was to the right of a peasant and was facing towards the peasant (peasant facing downwards), that peasant could move around etc and that footmen would continue to face that peasant. If that peasant faced upwards, the footmen would be on the left, etc... it's position is relative to the origin's x, y, z,
and facing =P.
I worked pretty hard on this script, but it was worth it =).
If anyone runs into any bugs w/ it, please let me know so I can fix them =P. I really scanned this over thoroughly in order to fix any logical errors, but you never now, I did it with very tired eyes so I could have missed sumtin =P.
On to Spawn and CombatSuite >: D.
Oh, and position types don't run in the timer >: P, so they are very good to use when you need positions relative to another position.
And you can ofc have positions relative to positions relative to more positions.
I was thinking of cool things, like a huge moving ship =P. This essentially allows pretty easy composite unit creation.
Keep in mind that the overhead on PositionOrigin is pretty hefty because it does have to run on a timer to keep everything in the right spot :\.
edit
optimized PositionOrigin a bit... went from lagging at 100 instances to smooth at 200. I don't suggest mass use of PositionOrigin with non position type positions >; p
With even 8000 position type positions, PositionOrigin would run smoothly because they aren't added to timer. Only lock unit positions to an origin or w/e for funky special effects =).
edit
another cool demo (spiral staircase thing)
JASS:
struct tests extends array
private static integer i = 100
private static Position p
private static real r = 0
private static integer is = 0
private static Position array pos
private static method ca takes nothing returns nothing
local integer x = is
loop
exitwhen x == 0
set x = x - 1
set pos[x].theta = pos[x].theta + .06283185
endloop
endmethod
private static method cr takes nothing returns nothing
local Position p2
local integer x = 50
set i = i - 50
if (i <= 0) then
set x = x + i
call PauseTimer(GetExpiredTimer())
call DestroyTimer(GetExpiredTimer())
endif
loop
exitwhen x == 0
set x = x - 1
set p2 = Position[CreateUnit(Player(0), 'hfoo', WorldBounds.centerX, WorldBounds.centerY, 180)]
set pos[is] = p2
set is = is + 1
call p2.lock()
set p2.origin = p
set p2.locked = true
set p2.theta = r
set p2.phi = 1.57079632
set p2.distance = 500
set p2.relative = false
set r = r + .06283185
set p2.z = is*5
endloop
endmethod
private static method onInit takes nothing returns nothing
set p = Position[CreateUnit(Player(0), 'hpea', WorldBounds.centerX, WorldBounds.centerY, 270)]
call p.lock()
set p.z = 500
call TimerStart(CreateTimer(), .03125, true, function thistype.cr)
call TimerStart(CreateTimer(), .03125, true, function thistype.ca)
endmethod
endstruct
edit
position types don't seem to be working right
also performed some updates to the script to remove a lot of code =)
edit
while fixing, I've been playing with it
Here is a rotating helix o-o
I made some cool ferris wheel thingies too, and if you uncomment the phi translation, this thing looks crazy Oo.
JASS:
struct tests extends array
private static constant integer A = 25
private static integer i = A
private static Position p
private static real r = 6.28318530/(A+0.)
private static integer is = 0
private static Position array pos
private static method ca takes nothing returns nothing
local integer x = is
local real h
local real m = p.x
local real v = p.y
loop
exitwhen x == 0
set x = x - 1
set pos[x].theta = pos[x].theta + .06283185
//set pos[x].phi = pos[x].phi + 0.1256637
//set h = pos[x].theta
//set pos[x].x = 250*Cos(h)+m
//set pos[x].y = 250*Sin(h)+v
endloop
endmethod
private static method cr takes nothing returns nothing
local Position p2
local Position p3
local integer x = 50
set i = i - 50
if (i <= 0) then
set x = x + i
call PauseTimer(GetExpiredTimer())
call DestroyTimer(GetExpiredTimer())
endif
loop
exitwhen x == 0
set x = x - 1
//set p3 = Position.create(0,0,0)
set p3 = Position[CreateUnit(Player(0), 'hfoo', WorldBounds.centerX, WorldBounds.centerY, 180)]
set pos[is] = p3
set is = is + 1
call p3.lock()
set p3.origin = p
set p3.locked = true
set p3.theta = r+1.57079632
set p3.phi = r
set p3.distance = 200
set p3.relative = false
set r = r + 6.28318530/(A+0.)
set p3.z = 300/(A+0.)*is
/*
set p2 = Position[CreateUnit(Player(0), 'hfoo', WorldBounds.centerX, WorldBounds.centerY, 180)]
call p2.lock()
set p2.origin = p3
set p2.locked = true
set p2.theta = 0
set p2.phi = 1.57079632
set p2.distance = 0
set p2.relative = true
*/
endloop
endmethod
private static method onInit takes nothing returns nothing
set p = Position[CreateUnit(Player(0), 'hpea', WorldBounds.centerX, WorldBounds.centerY, 270)]
call p.lock()
set p.z = 350
call TimerStart(CreateTimer(), .03125, true, function thistype.cr)
call TimerStart(CreateTimer(), .03125, true, function thistype.ca)
endmethod
endstruct
I really want to make a circle where the left side translates by phi one way and the right side translates by phi the other way, and I want to do so with minimal effort ; (.
I had a helix thing that was bending itself to create really psychedelic thingies, and that's what made me think that the circle would be cool.
Another cool shape would be a hyperbola ^)^, and a sphere where all of the thingies go towards the top and converge into a beam (a laser canon??).
I'm having too much fun with this... rofl