Arrow Keys to X and Y rotate the ship.
E and Q rotates the model by Z axis.
The current problem I am facing atm is, the ship rolls as its either facing down or up. Making me assume that it's stuck in first person mode. What I wanted to do is, get the ship to be able to pitch up and down, turn left and right, and roll reguardless of what angle its at.
I tried Faster 3D Rotation by Eclipzer but it was a no go.
Heres the code:
Code: Select all
#define SC_UP &h48
#define SC_LEFT &h4B
#define SC_RIGHT &h4D
#define SC_DOWN &h50
#define SC_Q &h10
#define SC_E &h12
#define pi 3.1415926535897932
TYPE V3D
X as Single
Y as Single
Z as Single
END TYPE
TYPE SimpleEnt
Rot as V3D
Coor as V3D
END TYPE
Type Edges
PointA as V3D
PointB as V3D
END TYPE
Declare SUB rotpt (x1!, y1!, z1!, rotx!, roty!, rotz!, nx!, ny!, nz!)
Declare SUB Point3D (xA!, yA!, zA!, xP, yP, DST)
CONST LENS = 384
CONST CenterX=320
CONST CenterY=240
Dim ToyLine(36) as Edges
Dim ToyVert(16) as V3D
Dim TempX, TempY, TempZ, RotPY, RotPX, RotPZ as Single
Dim Dist, ProjX(2), ProjY(2), PrevX, PrevY as Integer
DIM TOM, EEE as Integer
FOR TOM=1 to 16
READ ToyVert(TOM).X
READ ToyVert(TOM).Z
READ ToyVert(TOM).Y
ToyVert(TOM).Z=-ToyVert(TOM).Z
ToyVert(TOM).Y=-ToyVert(TOM).Y
NEXT TOM
For TOM =1 to 36
READ StartPNT
READ EndPNT
ToyLine(TOM).PointA.X=ToyVert(StartPNT+1).X
ToyLine(TOM).PointA.Y=ToyVert(StartPNT+1).Y
ToyLine(TOM).PointA.Z=ToyVert(StartPNT+1).Z
ToyLine(TOM).PointB.X=ToyVert(EndPNT+1).X
ToyLine(TOM).PointB.Y=ToyVert(EndPNT+1).Y
ToyLine(TOM).PointB.Z=ToyVert(EndPNT+1).Z
Next TOM
Screen 18
RotPY!=0
RotPX!=0
RotPZ!=0
DO
FOR EEE = 1 to 36
rotpt ToyLine(EEE).PointA.X,ToyLine(EEE).PointA.Y,ToyLine(EEE).PointA.Z,RotPX!,RotPY!,RotPZ!,TempX!,TempY!,TempZ!
Point3D TempX!, TempY!, TempZ!, ProjX(1), ProjY(1), Dist
rotpt ToyLine(EEE).PointB.X,ToyLine(EEE).PointB.Y,ToyLine(EEE).PointB.Z,RotPX!,RotPY!,RotPZ!,TempX!,TempY!,TempZ!
Point3D TempX!, TempY!, TempZ!, ProjX(2), ProjY(2), Dist
If Dist>0 Then
LINE (ProjX(1),ProjY(1))-(ProjX(2),ProjY(2)),15
END IF
NEXT EEE
SLEEP 1
CLS
Locate 5,5:Print "3D Wireframe Ship Test"
if multikey(SC_LEFT) then
RotPY!=RotPY!+.005
end if
if multikey(SC_Right) then
RotPY!=RotPY!-.005
end if
if multikey(SC_UP) then
RotPX!=RotPX!-.005
end if
if multikey(SC_Down) then
RotPX!=RotPX!+.005
end if
if multikey(SC_Q) then
RotPZ!=RotPZ!-.005
end if
if multikey(SC_E) then
RotPZ!=RotPZ!+.005
end if
Locate 1,1:Print RotPX!
Locate 2,1:Print RotPY!
Locate 3,1:Print RotPZ!
Loop Until Inkey$=" "
END
SUB Point3D (xA!, yA!, zA!, xP, yP, DST)
DST = (LENS - zA!)
xP=CenterX+(LENS * xA! / DST)
yP=CenterY+(LENS * yA! / DST)
END SUB
SUB rotpt (x1!, y1!, z1!, rotx!, roty!, rotz!, nx!, ny!, nz!)
DIM AS SINGLE rx,ry,rz
rx = rotx!
ry = roty!+90
rz = rotz!+90
'xrot
nx1! = x1!
ny1! = z1! * SIN(pi * rx) + y1! * COS(pi * rx)
nz1! = z1! * COS(pi * rx) - y1! * SIN(pi * rx)
'yrot
nx2! = nx1! * COS(pi * ry) - nz1! * SIN(pi * ry)
ny2! = ny1!
nz2! = nx1! * SIN(pi * ry) + nz1! * COS(pi * ry)
'zrot
nx! = nx2! * COS(pi * rz) - ny2! * SIN(pi * rz)
ny! = nx2! * SIN(pi * rz) + ny2! * COS(pi * rz)
nz! = nz2!
END SUB
Data -22,-203,-3
Data 22,-203,-3
Data -53,162,43
Data 53,162,43
Data 118,129,-19
Data 154,162,-3
Data -154,162,-3
Data -118,129,-19
Data -18,-142,10
Data 18,-142,10
Data 38,-51,11
Data -38,-51,11
Data 20,-51,43
Data -20,-51,43
Data 53,162,-3
Data -53,162,-3
Data 8,13
Data 8,11
Data 8,9
Data 9,12
Data 9,10
Data 0,11
Data 0,8
Data 0,7
Data 0,6
Data 0,1
Data 1,10
Data 1,9
Data 1,5
Data 1,4
Data 2,15
Data 2,13
Data 2,11
Data 2,6
Data 2,3
Data 3,14
Data 3,12
Data 3,10
Data 3,5
Data 4,14
Data 4,7
Data 4,5
Data 5,14
Data 5,10
Data 6,15
Data 6,11
Data 6,7
Data 7,15
Data 10,12
Data 11,13
Data 12,13
Data 14,15
Something like this:
'In the EEE loop:
GetPitchYawRoll RotX,RotY,RotZ,RealAngleX,RealAngleY,RealAngleZ
rotpt CoordX,CoordY,CoordZ,RealAngleX.RealAngleY.RealAngleZ,TempX,TempY,TempZ
'Where RealAngleX..Z get's their real rotation angle axis, and where TempX..Z gets a coordination of the offsetted rotational axises.
Really, how hard is this to solve?