Hi, I will present you my new baby
. A rotation plugin such as EZ-Rotate. I go a lightly different way as the author of ez-rotate but it works very good for me. I think it is for almost every a useful plugin.
Here the plugin download.
File:
eXtendetRotation-plugin_[en]_20111215.zip - 3.3 MB (Uploading)
Forum download
Here a demo download (Asteroidfield with an Elite like Scaner)
File:
xrot-Example.7z - 6.3 MB (Uploading)
Forum download
The Source code of the demo.
`Radar
`Radar.dba
`======================
`------------------------------------------------------
`------------------------------------------------------
`Defining some constants ...
`... for Images
#CONSTANT imgID_Mfd1 = 100
#CONSTANT imgID_Mfd2 = 101
#CONSTANT imgID_Mfd3 = 102
`... for Objects
#CONSTANT objID_AstroStart = 100
#CONSTANT objID_NumAstro = 300
`... for base values.
#CONSTANT Control_Sensitivity = 2.0
#CONSTANT Roll_Factor = 30.0
#CONSTANT Pitch_Factor = 20.0
#CONSTANT Speed_Max = 1.00
#CONSTANT Speed_Min = -0.5
#CONSTANT Thrust = 0.003
`An Asteroid Type
TYPE TAsteroid
iId AS INTEGER
vecPos AS DWORD
vecAxis AS DWORD
vecDir AS DWORD
vecRelPos AS DWORD
fRotSpeed# AS FLOAT
fMoveSpeed# AS FLOAT
fDistance# AS FLOAT
iHits AS INTEGER
ENDTYPE
`A Shot Type
TYPE TShot
iID AS INTEGER
fSpeed# AS FLOAT
iLifeTime as INTEGER
ENDTYPE
`Some Global Variables we need.
GLOBAL last_timer AS INTEGER
GLOBAL frametime AS INTEGER
GLOBAL target AS INTEGER
GLOBAL press AS INTEGER
GLOBAL speed_set# AS FLOAT
GLOBAL speed_current# AS FLOAT
GLOBAL screen_width AS DWORD
GLOBAL screen_height AS DWORD
GLOBAL mfd_width AS DWORD
GLOBAL mfd_height AS DWORD
GLOBAL mfds_width AS DWORD
GLOBAL mfds_height AS DWORD
GLOBAL radar_range# AS FLOAT
radar_range# = 500.0
target = objID_AstroStart
SYNC ON
SYNC RATE 120
AUTOCAM OFF
COLOR BACKDROP 0xff202030
SET CAMERA RANGE 0.1, 50000
screen_height = SCREEN HEIGHT()
screen_width = SCREEN WIDTH()
`Make a Camera for the right MFD.
MAKE CAMERA 1
SET CAMERA TO IMAGE 1, 1, 256, 256
`Extended-Rotation must be initialized.
XROT INITIALIZE
`Load Skybox
LOAD OBJECT "../../../Media/models/skybox/skybox.x", 1
SCALE OBJECT 1, 500000, 500000, 500000
SET OBJECT LIGHT 1, 0
`Load MFD
LOAD IMAGE "../../../Media/Textures/scanner-mfd.png", 100
LOAD IMAGE "../../../Media/Textures/MFD_1_green.png", 101
mfds_height = IMAGE HEIGHT(100)
mfds_width = IMAGE WIDTH(100)
mfd_height = IMAGE HEIGHT(101)
mfd_width = IMAGE WIDTH(101)
`Make Scanner
MAKE OBJECT PLAIN 2, 1, 1, 1
LOAD IMAGE "../../../Media/Textures/scanner.png", 2
TEXTURE OBJECT 2, 2
ROTATE LIMB 2, 0, 90, 0, 0
SET OBJECT TRANSPARENCY 2, 1
SET OBJECT LIGHT 2, 0
POSITION OBJECT 2, 0, -0.9, 2.2
LOCK OBJECT ON 2
SET OBJECT MASK 2, 1
`Create vector's and matrix for calculations
GLOBAL mat1 AS DWORD
GLOBAL vec1 AS DWORD
GLOBAL vec2 AS DWORD
GLOBAL vec3 AS DWORD
GLOBAL vecScanA AS DWORD
GLOBAL vecScanR AS DWORD
mat1 = DXMAT(0)
vec1 = DXVEC3(0)
vec2 = DXVEC3(0)
vec3 = DXVEC3(0)
vecScanR = DXVEC3(0, 0, -0.9, 2.2)
vecScanA = DXVEC3(0)
`Create asteroid data
DIM Asteroids(objID_NumAstro) AS TAsteroid
FOR n=1 TO objID_NumAstro
IF n=1 THEN LOAD OBJECT "../../../Media/models/Asteroids/AST_01.X", objID_AstroStart
IF n=2 THEN LOAD OBJECT "../../../Media/models/Asteroids/AST_02.X", objID_AstroStart+1
IF n=3 THEN LOAD OBJECT "../../../Media/models/Asteroids/AST_03.X", objID_AstroStart+2
IF n=4 THEN LOAD OBJECT "../../../Media/models/Asteroids/AST_04.X", objID_AstroStart+3
IF n=5 THEN LOAD OBJECT "../../../Media/models/Asteroids/AST_05.X", objID_AstroStart+4
IF n > 5 THEN CLONE OBJECT objID_AstroStart+n-1, objID_AstroStart+RND(4)
Asteroids(n).iId = objID_AstroStart+n-1
Asteroids(n).vecPos = DXVEC3(0, RND(2000)-1000, RND(2000)-1000, RND(2000)-1000)
Asteroids(n).vecAxis = DXVEC3(0, (RND(2000)-1000)/1000.0, (RND(2000)-1000)/1000.0, (RND(2000)-1000)/1000.0)
Asteroids(n).vecDir = DXVEC3(0, (RND(2000)-1000)/1000.0, (RND(2000)-1000)/1000.0, (RND(2000)-1000)/1000.0)
Asteroids(n).vecRelPos = DXVEC3(0)
Asteroids(n).fRotSpeed# = RND(100)/200.0
Asteroids(n).fMoveSpeed# = RND(100)/250.0
DXVEC3 NORMALIZE Asteroids(n).vecAxis, Asteroids(n).vecAxis
DXVEC3 NORMALIZE Asteroids(n).vecDir, Asteroids(n).vecDir
SCALE OBJECT Asteroids(n).iId, RND(30)+10, RND(30)+10, RND(30)+10
DBOBJ SET POSITION Asteroids(n).iId, Asteroids(n).vecPos
NEXT n
DO
time = TIMER()
frametime = time - last_timer
last_timer = time
Control()
UpdateAsteroids()
DrawCockpit()
`F1 - for some Info's
IF KEYSTATE(59)
PrintInfo()
ELSE
INK 0xffffffff, 0
TEXT 0, 0, "Hold F1 for some Info!"
ENDIF
SYNC
LOOP
`I don't need this stuff and release it. Prevent for memoryleaks.
DXMAT RELEASE mat1
DXVEC3 RELEASE vec1
FOR n=1 TO objID_NumAstro
DXVEC3 RELEASE Asteroids(n).vecAxis
DXVEC3 RELEASE Asteroids(n).vecPos
DXVEC3 RELEASE Asteroids(n).vecDir
DXVEC3 RELEASE Asteroids(n).vecRelPos
NEXT n
END
FUNCTION PrintInfo()
box 100, 100, 540, 380, 0x7f007f00, 0x7f007f00, 0x7f007f00, 0x7f007f00
INK 0xffffff00, 0
CENTER TEXT 320, 100, "Demonstrate Some cool Functions"
CENTER TEXT 320, 115, "-------------------------------------------------------"
CENTER TEXT 320, 145, "[E]-get closest asteroid."
CENTER TEXT 320, 160, "[R]-change scaner-range."
CENTER TEXT 320, 175, "[mouse-wheel]-set speed."
CENTER TEXT 320, 190, "[mouse]-control the ship."
CENTER TEXT 320, 205, "[mouse-button-middle]-set speed to zero."
CENTER TEXT 320, 235, "I had seen the 'Example5' of EZ-Rotate. Well, this is"
CENTER TEXT 320, 250, "my version of it."
CENTER TEXT 320, 280, "Asteroids rotating via vector-rotation and moving with"
CENTER TEXT 320, 295, "directional-vectors. Calculation of Scanner objects"
CENTER TEXT 320, 310, "with CALC ABSOLUT/RELATIVE POINT."
ENDFUNCTION
FUNCTION Control()
`Get mouse movement into variables mx#, my#, mz#
mx# = MOUSEMOVEX() / -Control_Sensitivity
my# = MOUSEMOVEY() / -Control_Sensitivity
mz# = MOUSEMOVEZ() / 1000.0
`If middle mousebutten pressed the set speed to zero.
IF MOUSECLICK() = 4 THEN speed_set# = 0.0
`setup the speed
speed_set# = speed_set# + mz#
IF speed_set# < Speed_Min then speed_set# = Speed_Min
IF speed_set# > Speed_Max THEN speed_set# = Speed_Max
add# = speed_set# - speed_current#
IF add# > Thrust THEN add# = Thrust
IF add# < -Thrust THEN add# = -Thrust
speed_current# = speed_current# + add#
MOVE CAMERA speed_current#
`pitch and roll control
IF mx# > Roll_Factor then mx# = Roll_Factor
IF mx# < -Roll_Factor THEN mx# = -Roll_Factor
IF my# > Pitch_Factor THEN my# = Pitch_Factor
IF my# < -Pitch_Factor THEN my# = -Pitch_Factor
`set radarrange with key 'R'
IF KEYSTATE(19) = 1 AND press = 0
radar_range# = radar_range# / 2
IF radar_range# < 125 THEN radar_range# = 500
press = 19
ELSE
IF KEYSTATE(19) = 0 AND press = 19 THEN press = 0
ENDIF
`Get the closest asteroid as target with key 'E'.
IF KEYSTATE(18) = 1 AND press = 0
dist# = 10000.0
FOR n = 1 TO objID_NumAstro
IF Asteroids(n).fDistance# < dist#
dist# = Asteroids(n).fDistance#
target = n
ENDIF
NEXT n
press = 18
ELSE
IF KEYSTATE(18) = 0 AND press = 18 THEN press = 0
ENDIF
`Set camera rotation and position.
DBCAM GET MATRIX mat1, 0
XROT LOCAL X mat1, mat1, my#
XROT LOCAL Z mat1, mat1, mx#
DBCAM SET MATRIX 0, mat1
DBOBJ SET POSITION 1, DBCAM GET POSITION(vec1, 0)
ENDFUNCTION
FUNCTION DrawCockpit()
`MFD - left
`Output some usefull data.
offY = screen_height-mfd_height
INK 0xffa0a0a0, 0
TEXT 35, offY+40, "S: "+str$(speed_current#, 2)+ " : "+str$(speed_set#, 2)
DBCAM GET POSITION vec1, 0
TEXT 35, offY+60, "P: x "+str$(DXVEC3X(vec1), 2)
TEXT 35, offY+70, " y "+str$(DXVEC3Y(vec1), 2)
TEXT 35, offY+80, " z "+str$(DXVEC3Z(vec1), 2)
DBCAM GET EULER vec1, 0
TEXT 35, offY+100, "R: x "+str$(DXVEC3X(vec1), 2)
TEXT 35, offY+110, " y "+str$(DXVEC3Y(vec1), 2)
TEXT 35, offY+120, " z "+str$(DXVEC3Z(vec1), 2)
TEXT 35, offY+140, "FPS: "+str$(SCREEN FPS())
PASTE IMAGE 101, 0, offY, 1
`MFD - mid
`Draw an elite-like scanner
offX = (screen_width/2)-(mfds_width/2)
`Rotate the 'scanner-image' in same direction as the camera
`For each asteroid
FOR n=1 TO objID_NumAstro
`If asteroid in scaner range ?
IF Asteroids(n).fDistance# <= radar_range#
`set color to red if the asteroid the target otherwise set grey
IF n = target THEN INK 0xffff0000, 0 ELSE ink 0xffa0a0a0, 0
`Calculate the position of the asteroid in the scaner and draw it
DXVEC3 DIV vec1, Asteroids(n).vecRelPos, (radar_range#*2.0)
DXVEC3 ADD vec2, vec1, vecScanR
XROT CALC ABSOLUT POSITION vec2, mat1, vec2
XROT CALC SCREEN POSITION vec3, 0, vec2
BOX DXVEC3X(vec3)-2, DXVEC3Y(vec3)-2, DXVEC3X(vec3)+2, DXVEC3Y(vec3)+2
`Draw the line from asteroid to y-axis base.
DXVEC3 ADD vec2, vecScanR, DXVEC3(vec2, DXVEC3X(vec1), 0.0, DXVEC3Z(vec1))
XROT CALC ABSOLUT POSITION vec2, mat1, vec2
XROT CALC SCREEN POSITION vec2, 0, vec2
LINE DXVEC3X(vec3), DXVEC3Y(vec3), DXVEC3X(vec2), DXVEC3Y(vec2)
ENDIF
NEXT n
INK 0xffa0a0a0, 0
TEXT offX+35, offY+40, "R: " + STR$(radar_range#, 0)+ " " + STR$(press)
PASTE IMAGE 100, offX, offY, 1
`MFD - right
`draw the target camera
offX = screen_width-mfd_width
DXVEC3 SUB vec1, DBOBJ GET POSITION(vec2, Asteroids(target).iId), DBCAM GET POSITION(vec3, 0)
fov# = DBCAM GET FOV(0)
size# = OBJECT SIZE(Asteroids(target).iId, 1)
sinfov# = SIN(fov#) * 3.0 * size#
camdist# = SQRT((sinfov#*sinfov#)-(size# * size#))
POSITION OBJECT Asteroids(target).iId, 0, 0, 10000
POSITION CAMERA 1, 0, 0, 10000.0 - camdist#
SYNC CAMERA 1
DBOBJ SET POSITION Asteroids(target).iId, vec2
PASTE IMAGE 1, offX, offY, 0
TEXT offX+35, offY+40, "OD: "+STR$(Asteroids(target).fDistance#, 3)
TEXT offX+35, offY+50, "OS: "+STR$(Asteroids(target).fMoveSpeed#, 3)
TEXT offX+35, offY+60, " m: "+STR$(size#*300.0, 3)+" t"
PASTE IMAGE 101, offX, offY, 1
ENDFUNCTION
FUNCTION UpdateAsteroids()
`Updating each Asteroid
FOR n=1 TO objID_NumAstro
`Get asteroid matrix.
`rotate it via vector-rotation and
`apply the rotation
DBOBJ GET MATRIX mat1, Asteroids(n).iId
XROT VECTOR ROTATION mat1, mat1, Asteroids(n).vecAxis, Asteroids(n).fRotSpeed#
DBOBJ SET ROTATION MATRIX objID_AstroStart+n-1, mat1
`set vec1 to movingdirection and multiply by speed
`add the result to current position of asteroid
`apply the new position to asteroid
DXVEC3 MUL vec1, Asteroids(n).vecDir, Asteroids(n).fMoveSpeed#
DXVEC3 ADD Asteroids(n).vecPos, Asteroids(n).vecPos, vec1
DBOBJ SET POSITION Asteroids(n).iId, Asteroids(n).vecPos
`store the relative position of the asteroid to the main camera.
`store the distance of the asteroid to the main camera.
XROT CALC RELATIVE POSITION Asteroids(n).vecRelPos, DBCAM GET MATRIX(mat1, 0), Asteroids(n).vecPos
dist# = DXVEC3 LENGTH(Asteroids(n).vecRelPos)
Asteroids(n).fDistance# = dist#
`let the asteroid fade out when it is to far.
fade# = (dist# - 1510.0)/5.0
IF fade# < 0.0 THEN fade# = 100.0 ELSE fade# = 100.0 - fade#
FADE OBJECT Asteroids(n).iId, fade#
`Make new asteroids if it go out.
IF ABS(dist#) > 2010.0 THEN NewAsteroid(n)
NEXT n
ENDFUNCTION
FUNCTION NewAsteroid(n AS INTEGER)
DXVEC3 Asteroids(n).vecAxis, (RND(2000)-1000)/1000.0, (RND(2000)-1000)/1000.0, (RND(2000)-1000)/1000.0
DXVEC3 Asteroids(n).vecDir, (RND(2000)-1000)/1000.0, (RND(2000)-1000)/1000.0, (RND(2000)-1000)/1000.0
Asteroids(n).fRotSpeed# = RND(100)/200.0
Asteroids(n).fMoveSpeed# = RND(100)/250.0
DXVEC3 NORMALIZE Asteroids(n).vecAxis, Asteroids(n).vecAxis
DXVEC3 NORMALIZE Asteroids(n).vecDir, Asteroids(n).vecDir
DXVEC3 MUL Asteroids(n).vecPos, Asteroids(n).vecDir, -2000.0
DXVEC3 ADD Asteroids(n).vecPos, Asteroids(n).vecPos, DBCAM GET POSITION(vec1, 0)
ENDFUNCTION
And the commands of the Plugin (over 160 commands). The most of them are only wrapped from the DirectX-SDK.
XROT
XROT INITIALIZE
XROT GLOBAL X
XROT GLOBAL Y
XROT GLOBAL Z
XROT LOCAL X
XROT LOCAL Y
XROT LOCAL Z
XROT MATRIX TO EULER
XROT ORBIT ROTATION
XROT VECTOR ROTATION
XROT ROTATE TO
XROT YAW TO
XROT PITCH TO
XROT CALC NORMAL
XROT REFLECT VECTOR
XROT CALC ABSOLUT POSITION
XROT CALC RELATIVE POSITION
XROT CALC SCREEN POSITION
XROT ALIGN AXIS TO NORMAL
XROT GET AXIS ANGLE BETWEEN VECTORS
DXVEC3
DXVEC3
DXVEC3X
DXVEC3Y
DXVEC3Z
DXVEC3$
DXVEC3 ADD
DXVEC3 MUL
DXVEC3 DIV
DXVEC3 BARY CENTRIC
DXVEC3 CATMUL ROM
DXVEC3 CROSS
DXVEC3 DOT
DXVEC3 HERMITE
DXVEC3 LENGTH
DXVEC3 LENGTH2
DXVEC3 LERP
DXVEC3 MAXIMIZE
DXVEC3 MINIMIZE
DXVEC3 NORMALIZE
DXVEC3 SCALE
DXVEC3 SUB
DXVEC3 TRANSFORM
DXVEC3 TRANSFORM NORMAL
DXVEC3 RELEASE
DXVEC3 CONVERT TO RADIANT
DXVEC3 CONVERT TO DEGREE
DXVEC3 NEGATE
DXMAT
DXMAT
DXMAT ROWCOL
DXMAT$
DXMAT IDENTITY
DXMAT AFFINE TRANSFORMATION
DXMAT DECOMPOSE
DXMAT DETERMINANT
DXMAT INVERSE
DXMAT IS IDENTITY
DXMAT LOOK AT LH
DXMAT LOOK AT RH
DXMAT MULTIPLY
DXMAT MULTIPLY TRANSPOSE
DXMAT ORTHO LH
DXMAT ORTHO RH
DXMAT ORTHO OFF CENTER LH
DXMAT ORTHO OFF CENTER RH
DXMAT PERSPECTIVE FOV LH
DXMAT PERSPECTIVE FOV RH
DXMAT PERSPECTIVE LH
DXMAT PERSPECTIVE RH
DXMAT PERSPECTIVE OFF CENTER LH
DXMAT PERSPECTIVE OFF CENTER RH
DXMAT REFLECT
DXMAT ROTATION AXIS
DXMAT ROTATION QUATERNION
DXMAT ROTATION YPR
DXMAT ROTATION X
DXMAT ROTATION Y
DXMAT ROTATION Z
DXMAT SCALING
DXMAT TRANSFORMATION
DXMAT TRANSLATION
DXMAT TRANSPOSE
DXMAT RELEASE
DXQUAT
DXQUAT
DXQUAT BARY CENTRIC
DXQUAT CONJUGATE
DXQUAT DOT
DXQUAT EXP
DXQUAT IDENTITY
DXQUAT INVERSE
DXQUAT IS IDENTITY
DXQUAT LENGTH
DXQUAT LENGTH2
DXQUAT LN
DXQUAT MULTIPLY
DXQUAT NORMALIZE
DXQUAT ROTATION AXIS
DXQUAT ROTATION MATRIX
DXQUAT ROTATION YPR
DXQUAT SLERP
DXQUAT SQUAD
DXQUAT SQUAD SETUP
DXQUAT TO AXIS ANGLE
DXQUAT TO EULER
DXQUAT RELEASE
DXQUATX
DXQUATY
DXQUATZ
DXQUATW
DXQUAT$
DXPLANE
DXPLANE
DXPLANE DOT COORD
DXPLANE DOT NORMAL
DXPLANE FROM POINT NORMAL
DXPLANE FROM POINTS
DXPLANE INTERSECT LINE
DXPLANE NORMALIZE
DXPLANE SCALE
DXPLANE TRANSFORM
DXPLANEA
DXPLANEB
DXPLANEC
DXPLANED
DXPLANE$
DBOBJ
DBOBJ GET POSITION
DBOBJ GET LOOK VECTOR
DBOBJ GET UP VECTOR
DBOBJ GET MATRIX
DBOBJ GET ROTATION MATRIX
DBOBJ GET TRANSLATION MATRIX
DBOBJ GET SCALE MATRIX
DBOBJ GET EULER
DBOBJ GET SCALE
DBOBJ SET ROTATION MATRIX
DBOBJ SET POSITION
DBOBJ SET ROTATION
DBOBJ MOVE
DBOBJ POINT TO
DBOBJ SET SCALE
DBOBJ GET SIZE
DBOBJ SET COLLISION BOX
DBOBJ INTERSECT
DBOBJ SET OFFSET LIMB
DBOBJ SET ROTATION LIMB
DBOBJ SET SCALE LIMB
DBOBJ GET OFFSET LIMB
DBOBJ GET SCALE LIMB
DBOBJ GET ANGLE LIMB
DBOBJ GET DIRECTION LIMB
DBOBJ GET POSITION LIMB
DBOBJ SET SIZE
DBCAM
DBCAM GET MATRIX
DBCAM GET PROJECTION MATRIX
DBCAM GET VIEW MATRIX
DBCAM GET LOOK VECTOR
DBCAM GET UP VECTOR
DBCAM GET RIGHT VECTOR
DBCAM GET POSITION
DBCAM GET EULER
DBCAM GET ASPECT
DBCAM GET FOV
DBCAM SET ROTATION
DBCAM SET POSITION
DBCAM SET MATRIX
DBCAM SET PROJECTION MATRIX
DBCAM SET ORTHOGONAL MATRIX
DBCAM POINT TO
DBCAM MOVE
Questions, suggestions and comments are welcome. I hope you find not many bugs
With Computers you can solve Problems that you have never befor.
Share your knowledge. It's a way to achieve immortality. (Tenzin Gyatso)