Warcraft III resources & community, 2003–2006 · archived

3d functions

not rated
Submitted by N-a-z-g-u-lPhysics0 downloads
Here are some 3d functions. See below for what you can use them. All functions can be used without the others.

By myself i am only using Distance3DBetweenUnits() for a 3d damage area. Another one i used, but nut as a function, was the 3d polar projection for creating lightnings in a ball.

I hope these functions can help you, because Warcraft III does not allow you to do the most things in a 3d room.

Source

function PolarProjection3DX takes real FromX, real FromY, real FromZ, real Dist, real Angle, real AngleZ returns real
	// Returns the X-coordinate of a 3d polar projection
	return FromX + ( FromZ + Dist * Cos(AngleZ * bj_DEGTORAD) ) * Cos(Angle * bj_DEGTORAD)
endfunction

function PolarProjection3DY takes real FromX, real FromY, real FromZ, real Dist, real Angle, real AngleZ returns real
	// Returns the Y-coordinate of a 3d polar projection
	return FromY + ( FromZ + Dist * Cos(AngleZ * bj_DEGTORAD) ) * Sin(Angle * bj_DEGTORAD)
endfunction

function PolarProjection3DZ takes real FromX, real FromY, real FromZ, real Dist, real Angle, real AngleZ returns real
	// Returns the Z-coordinate of a 3d polar projection
	// This function does not need all its parameters, but it is easier to handle with all parameters
	return FromZ + Dist * Sin(AngleZ * bj_DEGTORAD)
endfunction

function Distance3DBetweenCoordinates takes real FromX, real FromY, real FromZ, real ToX, real ToY, real ToZ returns real
	// Returns the 3d-distance between two 3d-coordinates
	local real DistX = ToX - FromX
	local real DistY = ToY - FromY
	local real DistZ = ToZ - FromZ
	return SquareRoot( DistX * DistX + DistY * DistY + DistZ * DistZ )
endfunction

function Distance3DBetweenUnits takes unit Unit1, unit Unit2 returns real
	// Returns the 3d-distance between two 3d-coordinates
	// The distance may be wrong, when a ground-unit is flying over water,
	// because GetLocationZ returns the height of water then
	// This problem does not match to flying, floating or amphibious units
	local location Loc1 = GetUnitLoc( Unit1 )
	local location Loc2 = GetUnitLoc( Unit2 )
	local real DistX = GetLocationX( Loc2 ) - GetLocationX( Loc1 )
	local real DistY = GetLocationY( Loc2 ) - GetLocationY( Loc1 )
	local real DistZ = GetLocationZ( Loc2 ) - GetLocationZ( Loc1 ) + GetUnitFlyHeight( Unit2 ) - GetUnitFlyHeight( Unit1 )
	call RemoveLocation( Loc1 )
	call RemoveLocation( Loc2 )
	set Loc1 = null
	set Loc2 = null
	return SquareRoot( DistX * DistX + DistY * DistY + DistZ * DistZ )
endfunction

Comments

2
You can get the terrain cliff level, but i dont think there is something like GetLocationZ()... if there were another, i would have used
I would use GetUnitX and GetUnitY in the Distance3DBetweenUnits function to avoit using locations. Isn't there a GetTerrainHeightLevel function? It would replace GetLocationZ.