Dirac
22710180
- Reaction score
- 147
vCircles is a very useful snippet for spinning points around bidimensional cicles or tridimensional spheres. It's very fast and has the capacity of calculating distances across the circle's perimeter, so if you want to move a projectile for, lets say, 40 units around a perimeter, with vCircles you can.
Graphical explanations of how to use it coming soon. Enjoy!
JASS:
library vCircles
//**************************************************************************************************************************
//Snippet made by Dirac to avoid polar offset positioning
// This creates a circle around a point with a base angle 0. this angle determines the offset location
// of the point you might need to move or create something.
//Variables:
// real x
// -center X
// real y
// -center Y
// real radius
// -radius of the circle
// real xyangle
// -current angle in the x axis
// real zangle
// -current angle in the z axis
//Read only values:
// real offsetX
// -the X depending on the circle's radius and current angle
// real offsetY
// -the Y depending on the circle's radius and current angle
// real offsetZ
// -the Z depending on the circle's height.
// real xyspin
// -the amount of spins done in the x axis.
// real zspin
// -the amount of spins done in the z axis.
//Setting up values
// set baseX=radians
// -Sets the xyangle base rotation to a value
//Methods:
// static method create takes real x, real y, real z, real radius returns thistype
// -Imput here the center x,y,z and radius, default angle is 0, you can change that later
// method radiusVector takes real howMuch, real radians returns nothing
// -This method reduces or increases the radius lenght towards an angle
// -The angle is measured starting from the edge of the circle, a few examples:
// if the angle provided is 0 the radius would increase exactly by the amount provided,
// if the angle provided is 180 the radius would decrease exactly by the amount provided,
// if the angle provided is 90 the radius would increase sightly
// method polarVector2d takes real howMuch, boolean clockwise returns nothing
// -This method moves the circle angle around it's radius depending on the amount provided
// -This is a very good way to avoid polar offset when you wan't to move something exactly
// by an amount of distance around a point, not an angle.
// method polarVector3d takes real howMuch, real radians returns nothing
// -This method moves the offset of the point by the amount provided towards the angle
// provided around the sphere. Use this if you care about the distance the point moves
// method polarSpin3d takes real radiansX, real radiansZ returns nothing
// -This method spins the offset of the point around the X and Z axis towards the angle
// provided. Use this to give a smooth movement around the circle.
//**************************************************************************************************************************
struct circle
real x
real y
real z
real radius
real xyangle
real zangle
readonly real xyspin
readonly real zspin
private real xBase
static method create takes real x, real y,real z, real radius returns thistype
local thistype this=thistype.allocate()
set .x=x
set .y=y
set .z=z
set .xyangle=0
set .zangle=0
set .xyspin=0
set .zspin=0
set .xBase=0
set .radius=radius
return this
endmethod
method operator baseX= takes real radians returns nothing
set .xyangle=.xyangle+radians-.xBase
set .xBase=radians
endmethod
method operator offsetZ takes nothing returns real
return .z+.radius*Sin(.zangle)
endmethod
method operator offsetX takes nothing returns real
return .radius*Cos(.xyangle)*Cos(.zangle)+.x
endmethod
method operator offsetY takes nothing returns real
return .radius*Sin(.xyangle)*Cos(.zangle)+.y
endmethod
method radiusVector takes real howMuch,real radians returns nothing
local real A=.radius
set .radius=SquareRoot(.radius*.radius+howMuch*howMuch-2*howMuch*.radius*Cos(bj_PI-radians))
set .z=.z+.radius-A
endmethod
method polarVector2d takes real howMuch, boolean clockwise returns nothing
local real a=2*Asin(howMuch/(2*.radius))/RAbsBJ(Cos(.zangle))
if clockwise==false then
set .xyangle=.xyangle+a
else
set .xyangle=.xyangle-a
endif
set .xyspin=.xyspin+a
endmethod
method polarVector3d takes real howMuch, real radians returns nothing
local real a=2*Asin(howMuch/(2*.radius))*Cos(radians)/RAbsBJ(Cos(.zangle))
local real b=2*Asin(howMuch/(2*.radius))*Sin(radians)
set .xyangle=.xyangle+a
set .zangle=.zangle+b
set .xyspin=.xyspin+a
set .zspin=.zspin+b
endmethod
method polarSpin3d takes real radiansX, real radiansZ returns nothing
set .xyangle=.xyangle+radiansX
set .zangle=.zangle+radiansZ
set .xyspin=.xyspin+radiansX
set .zspin=.zspin+radiansZ
endmethod
endstruct
endlibrary
Graphical explanations of how to use it coming soon. Enjoy!
Attachments
-
59.4 KB Views: 307