$TYPECHECK ON
$IFNDEF False
$DEFINE False 0
$ENDIF
$IFNDEF True
$DEFINE True 1
$ENDIF
$IFNDEF D3DVALUE
$DEFINE D3DVALUE SINGLE
$ENDIF
$IFNDEF D3DVECTOR
TYPE D3DVECTOR
X AS SINGLE
Y AS SINGLE
Z AS SINGLE
END TYPE
$DEFINE LPD3DVECTOR LONG
$ENDIF
TYPE Q3DVECTOR
DVX AS SINGLE
DVY AS SINGLE
DVZ AS SINGLE
X AS SINGLE
Y AS SINGLE
Z AS SINGLE
END TYPE
TYPE QD3DORIENTVECTOR
X AS SINGLE
Y AS SINGLE
Z AS SINGLE
DVX AS SINGLE
DVY AS SINGLE
DVZ AS SINGLE
END TYPE
TYPE QD3DRGBA
R AS SINGLE
G AS SINGLE
B AS SINGLE
A AS SINGLE
END TYPE
CONST D3DGROUND_ZERO = 0
CONST D3DRMWRAP_FLAT = 0
CONST D3DRMWRAP_CYLINDER = 1
CONST D3DRMWRAP_SPHERE = 2
CONST D3DRMWRAP_CHROME = 3
CONST D3DRMWRAP_SHEET = 4
CONST D3DRMWRAP_BOX = 5
CONST D3DRMLIGHT_AMBIENT = 0
CONST D3DRMLIGHT_POINT = 1
CONST D3DRMLIGHT_SPOT = 2
CONST D3DRMLIGHT_DIRECTIONAL = 3
CONST D3DRMLIGHT_PARALLELPOINT = 4
CONST D3DRMSHADE_FLAT = 0
CONST D3DRMSHADE_GOURAUD = 1
CONST D3DRMSHADE_PHONG = 2
CONST D3DRMSHADE_MASK = 7
CONST D3DRMSHADE_MAX = 8
CONST D3DRMFILL_POINTS = 0
CONST D3DRMFILL_WIREFRAME = 64
CONST D3DRMFILL_SOLID = 128
CONST D3DRMFILL_MASK = 448
CONST D3DRMFILL_MAX = 512
CONST D3DRMLIGHT_OFF = 0 * D3DRMSHADE_MAX
CONST D3DRMLIGHT_ON = 1 * D3DRMSHADE_MAX
CONST D3DRMLIGHT_MASK = 7 * D3DRMSHADE_MAX
CONST D3DRMLIGHT_MAX = 8 * D3DRMSHADE_MAX
CONST D3DRMRENDER_POINTS = D3DRMSHADE_FLAT + D3DRMLIGHT_OFF + D3DRMFILL_POINTS
CONST D3DRMRENDER_WIREFRAME = D3DRMSHADE_FLAT + D3DRMLIGHT_OFF + D3DRMFILL_WIREFRAME
CONST D3DRMRENDER_UNLITFLAT = D3DRMSHADE_FLAT + D3DRMLIGHT_OFF + D3DRMFILL_SOLID
CONST D3DRMRENDER_FLAT = D3DRMSHADE_FLAT + D3DRMLIGHT_ON + D3DRMFILL_SOLID
CONST D3DRMRENDER_GOURAUD = D3DRMSHADE_GOURAUD + D3DRMLIGHT_ON + D3DRMFILL_SOLID
CONST D3DRMRENDER_PHONG = D3DRMSHADE_PHONG + D3DRMLIGHT_ON + D3DRMFILL_SOLID
CONST D3DRMRENDER_MAX = D3DRMSHADE_PHONG + D3DRMLIGHT_ON + D3DRMFILL_MAX
CONST D3DRMWIREFRAME_CULL = 1
CONST D3DRMWIREFRAME_HIDDENLINE = 2
CONST D3DRMRENDERMODE_BLENDEDTRANSPARENCY = 1
CONST D3DRMRENDERMODE_SORTEDTRANSPARENCY = 2
CONST D3DRMRENDERMODE_LIGHTINMODELSPACE = 8
CONST D3DRMRENDERMODE_VIEWDEPENDENTSPECULAR = 16
CONST D3DRMRENDERMODE_DISABLESORTEDALPHAZWRITE = 32
CONST D3DRMTEXTURE_FORCERESIDENT = &H00000001
CONST D3DRMTEXTURE_STATIC = &H02
CONST D3DRMTEXTURE_DOWNSAMPLEPOINT = &H00000004
CONST D3DRMTEXTURE_DOWNSAMPLEBILINEAR = &H00000008
CONST D3DRMTEXTURE_DOWNSAMPLEREDUCEDEPTH = &H00000010
CONST D3DRMTEXTURE_DOWNSAMPLENONE = &H00000020
CONST D3DRMTEXTURE_CHANGEDPIXELS = &H00000040
CONST D3DRMTEXTURE_CHANGEDPALETTE = &H00000080
CONST D3DRMTEXTURE_INVALIDATEONLY = &H00000100
CONST D3DRMTEXTURE_NEAREST = 0
CONST D3DRMTEXTURE_LINEAR = 1
CONST D3DRMTEXTURE_MIPNEAREST = 2
CONST D3DRMTEXTURE_MIPLINEAR = 3
CONST D3DRMTEXTURE_LINEARMIPNEAREST = 4
CONST D3DRMTEXTURE_LINEARMIPLINEAR = 5
CONST D3DRMSHADOW_TRUEALPHA = &H00000001
CONST D3DRMFOG_LINEAR = 0
CONST D3DRMFOG_EXPONENTIAL = 1
CONST D3DRMFOG_EXPONENTIALSQUARED = 2
CONST D3DRMCONSTRAIN_Z = 0
CONST D3DRMCONSTRAIN_Y = 1
CONST D3DRMCONSTRAIN_X = 2
CONST D3DRMCOMBINE_REPLACE = 0
CONST D3DRMCOMBINE_BEFORE = 1
CONST D3DRMCOMBINE_AFTER = 2
DECLARE SUB D3DRMVectorCrossProduct LIB "d3drm.dll" ALIAS "D3DRMVectorCrossProduct"_
(ByRef d AS D3DVECTOR, ByRef s1 AS D3DVECTOR, ByRef s2 AS D3DVECTOR)
DECLARE SUB CrossProduct(BYREF Norm AS QD3DVECTOR, BYREF a AS QD3DVECTOR, BYREF b AS QD3DVECTOR)
SUB CrossProduct(BYREF a AS QD3DVECTOR, BYREF b AS QD3DVECTOR, BYREF Norm AS QD3DVECTOR)
Norm.x = a.y * b.z - a.z * b.y
Norm.y = a.z * b.x - a.x * b.z
Norm.z = a.x * b.y - a.y * b.x
END SUB
DECLARE FUNCTION D3DRMVectorDotProduct LIB "d3drm.dll" ALIAS "D3DRMVectorDotProduct" _
(ByRef s1 AS D3DVECTOR, ByRef s2 AS D3DVECTOR) AS D3DVALUE
DECLARE FUNCTION VectorDotProduct(BYREF a AS QD3DVECTOR, BYREF b AS QD3DVECTOR) AS SINGLE
FUNCTION VectorDotProduct(BYREF a AS QD3DVECTOR, BYREF b AS QD3DVECTOR) AS SINGLE
VectorDotProduct = a.x * b.x + a.y * b.y + a.z * b.z
END FUNCTION
DECLARE FUNCTION D3DRMVectorNormalize LIB "d3drm.dll" ALIAS "D3DRMVectorNormalize"_
(ByRef lpD3DVECTOR AS D3DVECTOR ) AS LPD3DVECTOR
DECLARE SUB VectorNormalize(BYREF VecIn AS QD3DVECTOR)
SUB VectorNormalize(BYREF VecIn AS QD3DVECTOR)
DIM VLength AS SINGLE
VLength = VecIn.x * VecIn.x + VecIn.y * VecIn.y + VecIn.z * VecIn.z
IF VLength = 0 THEN VecIn.x = 0: VecIn.y = 0: VecIn.z = 0: EXIT SUB
VLength = SQR(VLength)
VecIn.x = VecIn.x / VLength
VecIn.y = VecIn.y / VLength
VecIn.z = VecIn.z / VLength
END SUB
DECLARE SUB VectorAdd(BYREF VectAdd AS QD3DVECTOR, BYREF a AS QD3DVECTOR, BYREF b AS QD3DVECTOR)
SUB VectorAdd(BYREF VectAdd AS QD3DVECTOR, BYREF a AS QD3DVECTOR, BYREF b AS QD3DVECTOR)
VectAdd.x = a.x + b.x
VectAdd.y = a.y + b.y
VectAdd.z = a.z + b.z
END SUB
DECLARE SUB VectorSubtract(BYREF VectSub AS QD3DVECTOR, BYREF a AS QD3DVECTOR, BYREF b AS QD3DVECTOR)
SUB VectorSubtract(BYREF VectSub AS QD3DVECTOR, BYREF a AS QD3DVECTOR, BYREF b AS QD3DVECTOR)
VectSub.x = a.x - b.x
VectSub.y = a.y - b.y
VectSub.z = a.z - b.z
END SUB
$DEFINE null ""
TYPE QD3DCamera EXTENDS QOBJECT
PRIVATE:
PushMouseX AS INTEGER
PushMouseY AS INTEGER
PUBLIC:
POS AS QD3DVECTOR
Orient AS QD3DOrientVector
Height AS SINGLE
ZoomFactor AS SINGLE
AngleX AS INTEGER
AngleY AS INTEGER
MouseDownButton AS INTEGER
MouseDownX AS INTEGER
MouseDownY AS INTEGER
MouseZooming AS INTEGER
FUNCTION GetRadius() AS SINGLE
QD3DCamera.GetRadius = SQR(QD3DCamera.POS.x * QD3DCamera.POS.x +_
QD3DCamera.POS.y * QD3DCamera.POS.y +_
QD3DCamera.POS.z * QD3DCamera.POS.z)
END FUNCTION
FUNCTION GetXZRadius() AS SINGLE
QD3DCamera.GetXZRadius = SQR(QD3DCamera.POS.x * QD3DCamera.POS.x +_
QD3DCamera.POS.z * QD3DCamera.POS.z)
END FUNCTION
FUNCTION GetXYRadius() AS SINGLE
QD3DCamera.GetXYRadius = SQR(QD3DCamera.POS.x * QD3DCamera.POS.x +_
QD3DCamera.POS.y * QD3DCamera.POS.y)
END FUNCTION
SUB Translate(dx AS SINGLE, dy AS SINGLE, dz AS SINGLE)
QD3DCamera.POS.x = QD3DCamera.POS.x + dx
QD3DCamera.POS.y = QD3DCamera.POS.y + dy
QD3DCamera.POS.z = QD3DCamera.POS.z + dz
END SUB
SUB ZoomXZ(Mag AS SINGLE)
QD3DCamera.POS.x = QD3DCamera.POS.x + (QD3DCamera.Orient.x * Mag)
QD3DCamera.POS.z = QD3DCamera.POS.z + (QD3DCamera.Orient.z * Mag)
END SUB
SUB Zoom(Mag AS SINGLE)
QD3DCamera.POS.x = QD3DCamera.POS.x + (QD3DCamera.Orient.x * Mag)
QD3DCamera.POS.z = QD3DCamera.POS.z + (QD3DCamera.Orient.z * Mag)
QD3DCamera.POS.y = QD3DCamera.POS.y + (QD3DCamera.Orient.y * Mag)
END SUB
SUB ResetView
QD3DCamera.Orient.x = 0.0
QD3DCamera.Orient.y = 0.0
QD3DCamera.Orient.z = 1.0
QD3DCamera.Orient.dvx = 0.0
QD3DCamera.Orient.dvy = 1.0
QD3DCamera.Orient.dvz = 0.0
QD3DCamera.AngleX = 0
QD3DCamera.AngleY = 0
END SUB
SUB FaceCamera(BYREF Orient AS QD3DOrientVector, ObjPosX AS SINGLE, ObjPosY AS SINGLE, ObjPosZ AS SINGLE)
DIM Delta AS QD3DVECTOR
DIM Radi AS SINGLE
Delta.X = ObjPosX - QD3DCamera.POS.x
Delta.Y = ObjPosY - QD3DCamera.POS.y
Delta.Z = ObjPosZ - QD3DCamera.POS.z
Orient.dvx = QD3DCamera.Orient.dvx
Orient.dvy = QD3DCamera.Orient.dvy
Orient.dvz = QD3DCamera.Orient.dvz
Radi = SQR(Delta.x*Delta.x + Delta.y*Delta.y + Delta.z*Delta.z)
IF Radi < 0.01 THEN EXIT SUB
Orient.x = Delta.X/Radi
Orient.z = Delta.z/Radi
Orient.y = Delta.Y/Radi
END SUB
SUB Update (DxScrn AS QDXSCREEN)
DxScrn.SetCameraPosition(QD3DCamera.POS.x, QD3DCamera.POS.y, QD3DCamera.POS.z)
DxScrn.SetCameraOrientation(QD3DCamera.Orient.x, QD3DCamera.Orient.y, QD3DCamera.Orient.z,_
QD3DCamera.Orient.dvx, QD3DCamera.Orient.dvy, QD3DCamera.Orient.dvz)
END SUB
SUB SaveMouse
QD3DCamera.PushMouseX = QD3DCamera.MouseDownX
QD3DCamera.PushMouseY = QD3DCamera.MouseDownY
END SUB
SUB RestoreMouse
SetCursorPos(QD3DCamera.PushMouseX, QD3DCamera.PushMouseY)
END SUB
CONSTRUCTOR
POS.x = 0.0
POS.y = 0.0
POS.z = 0.0
Orient.x = 0.0
Orient.y = 0.0
Orient.z = 1.0
Orient.dvx = 0.0
Orient.dvy = 1.0
Orient.dvz = 0.0
Height = 1.0
ZoomFactor = 1.0
AngleX = 0
AngleY = 0
MouseDownButton = MouseNotDown
MouseDownX = 0
MouseDownY = 0
MouseZooming = False
END CONSTRUCTOR
END TYPE
TYPE QD3DPrimitive EXTENDS QOBJECT
PRIVATE:
xc AS SINGLE
yc AS SINGLE
zc AS SINGLE
PUBLIC:
Mesh AS QD3DMESHBUILDER
Frame AS QD3DFRAME
RenderQuality AS LONG
TextureFile AS STRING
TexOriginX AS SINGLE
TexOriginY AS SINGLE
TexOriginZ AS SINGLE
TexOriginU AS SINGLE
TexOriginV AS SINGLE
TexScaleU AS SINGLE
TexScaleV AS SINGLE
TexWrapType AS SHORT
COLOR AS QD3DRGBA
DrawCenter AS QD3DVECTOR
BoxSides AS INTEGER
ViewFromOutside AS INTEGER
Visible AS INTEGER
FUNCTION New() AS INTEGER
WITH QD3DPrimitive
.RenderQuality = D3DRMRENDER_FLAT
.TextureFile = null
.TexOriginX = 0.0
.TexOriginY = 0.0
.TexOriginZ = 0.0
.TexOriginU = 0.0
.TexOriginV = 0.0
.TexScaleU = 1.0
.TexScaleV = 1.0
.TexWrapType = D3DRMWRAP_SPHERE
.COLOR.R = 1.0
.COLOR.G = 1.0
.COLOR.B = 1.0
.COLOR.A = 1.0
.DrawCenter.x = 0.0
.DrawCenter.y = 0.0
.DrawCenter.z = 0.0
.BoxSides = 5
.ViewFromOutside = True
.Visible = False
END WITH
END FUNCTION
SUB LoadTextureFile
DIM openDialog AS QOPENDIALOG
IF QD3DPrimitive.TextureFile = null THEN
openDialog.CAPTION = "select a bitmap for the texture"
openDialog.filter = "*.bmp (bitmaps)|*.bmp"
IF openDialog.EXECUTE THEN
IF FILEEXISTS(openDialog.fileName) THEN
QD3DPrimitive.TextureFile = openDialog.fileName
ELSE
SHOWMESSAGE "Texture file does not exist"
EXIT SUB
END IF
END IF
END IF
QD3DPrimitive.Mesh.loadTexture(QD3DPrimitive.TextureFile)
END SUB
SUB MakeHorizPlane(DXScreen AS QDXSCREEN)
DIM Face AS QD3DFACE
DIM xc AS SINGLE
DIM yc AS SINGLE
DIM zc AS SINGLE
xc = QD3DPrimitive.DrawCenter.x
yc = QD3DPrimitive.DrawCenter.y
zc = QD3DPrimitive.DrawCenter.z
DXScreen.CreateFace(Face)
IF QD3DPrimitive.ViewFromOutside THEN
Face.AddVertex(-1+xc, 0+yc, -1): Face.AddVertex( 1+xc, 0+yc, -1)
Face.AddVertex( 1+xc, 0+yc, 1): Face.AddVertex(-1+xc, 0+yc, 1)
ELSE
Face.AddVertex(-1+xc, 0+yc, 1): Face.AddVertex( 1+xc, 0+yc, 1)
Face.AddVertex( 1+xc, 0+yc, -1): Face.AddVertex(-1+xc, 0+yc, -1)
END IF
QD3DPrimitive.Mesh.AddFace(Face)
QD3DPrimitive.Visible = True
END SUB
SUB MakeVertZPlane(DXScreen AS QDXSCREEN)
DIM Face AS QD3DFACE
DIM xc AS SINGLE
DIM yc AS SINGLE
DIM zc AS SINGLE
xc = QD3DPrimitive.DrawCenter.x
yc = QD3DPrimitive.DrawCenter.y
zc = QD3DPrimitive.DrawCenter.z
DXScreen.CreateFace(Face)
IF QD3DPrimitive.ViewFromOutside THEN
Face.AddVertex(xc, 0+yc, -1+zc): Face.AddVertex(xc, 1+yc, -1+zc)
Face.AddVertex(xc, 1+yc, 1+zc): Face.AddVertex(xc, 0+yc, 1+zc)
ELSE
Face.AddVertex(xc, 0+yc, 1+zc): Face.AddVertex(xc, 1+yc, 1+zc)
Face.AddVertex(xc, 1+yc, -1+zc): Face.AddVertex(xc, 0+yc, -1+zc)
END IF
QD3DPrimitive.Mesh.AddFace(Face)
QD3DPrimitive.Visible = True
END SUB
SUB MakeVertXPlane(DXScreen AS QDXSCREEN)
DIM Face AS QD3DFACE
DIM xc AS SINGLE
DIM yc AS SINGLE
DIM zc AS SINGLE
xc = QD3DPrimitive.DrawCenter.x
yc = QD3DPrimitive.DrawCenter.y
zc = QD3DPrimitive.DrawCenter.z
DXScreen.CreateFace(Face)
IF QD3DPrimitive.ViewFromOutside = True THEN
Face.AddVertex( 1+xc, 0+yc, zc): Face.AddVertex( 1+xc, 1+yc, zc)
Face.AddVertex(-1+xc, 1+yc, zc): Face.AddVertex(-1+xc, 0+yc, zc)
ELSE
Face.AddVertex(-1+xc, 0+yc, zc): Face.AddVertex(-1+xc, 1+yc, zc)
Face.AddVertex( 1+xc, 1+yc, zc): Face.AddVertex( 1+xc, 0+yc, zc)
END IF
QD3DPrimitive.Mesh.AddFace(Face)
QD3DPrimitive.Visible = True
END SUB
SUB MakeBox(DXScreen AS QDXSCREEN)
DIM Face AS QD3DFACE
DIM tmp AS QD3DVECTOR
DIM tmpView AS INTEGER
WITH QD3DPrimitive
tmp.x = .DrawCenter.x
tmp.y = .DrawCenter.y
tmp.z = .DrawCenter.z
tmpView = .ViewFromOutside
.DrawCenter.z = 1
.MakeVertXPlane(DXScreen)
IF .ViewFromOutside = True THEN .ViewFromOutside = False ELSE .ViewFromOutside = True
.DrawCenter.z = -1
.MakeVertXPlane(DXScreen)
.ViewFromOutside = tmpView
IF .ViewFromOutside = True THEN .ViewFromOutside = False ELSE .ViewFromOutside = True
.DrawCenter.z = 0
.DrawCenter.x = -1
.MakeVertZPlane(DXScreen)
.ViewFromOutside = tmpView
.DrawCenter.x = 1
.MakeVertZPlane(DXScreen)
IF .BoxSides > 4 THEN
IF .ViewFromOutside = True THEN .ViewFromOutside = False ELSE .ViewFromOutside = True
.DrawCenter.z = 0
.DrawCenter.x = 0
.DrawCenter.y = 1
.MakeHorizPlane(DXScreen)
.ViewFromOutside = tmpView
END IF
IF .BoxSides > 5 THEN
.DrawCenter.y = 0
.MakeHorizPlane(DXScreen)
END IF
.DrawCenter.x = tmp.x
.DrawCenter.y = tmp.y
.DrawCenter.z = tmp.z
.ViewFromOutside = tmpView
.Visible = True
END WITH
END SUB
SUB MakePyramid(DXScreen AS QDXSCREEN)
DIM Face AS QD3DFACE
WITH QD3DPrimitive
DXScreen.CreateFace(Face)
Face.AddVertex(0, 0, 0)
Face.AddVertex(1, 1, 1)
Face.AddVertex(1, -1, 1)
IF .ViewFromOutside = False THEN
Face.AddVertex(1, 1, 1)
END IF
.Mesh.AddFace(Face)
Face.AddVertex( 0, 0, 0)
Face.AddVertex( 1, 1, 1)
Face.AddVertex(-1, 1, 1)
IF .ViewFromOutside = False THEN
Face.AddVertex( 1, 1, 1)
END IF
.Mesh.AddFace(Face)
Face.AddVertex( 0, 0, 0)
Face.AddVertex(-1, 1, 1)
Face.AddVertex(-1, -1, 1)
IF .ViewFromOutside = False THEN
Face.AddVertex(-1, 1, 1)
END IF
.Mesh.AddFace(Face)
Face.AddVertex( 0, 0, 0)
Face.AddVertex(-1, -1, 1)
Face.AddVertex( 1, -1, 1)
IF .ViewFromOutside = False THEN
Face.AddVertex(-1, -1, 1)
END IF
.Mesh.AddFace(Face)
.Visible = True
END WITH
END SUB
SUB MakeSphere(DXScreen AS QDXSCREEN, NumFaces AS INTEGER)
DIM Phi AS SINGLE
DIM Theta AS SINGLE
DIM theStep AS SINGLE
DIM theStep2 AS SINGLE
DIM x1 AS SINGLE, y1 AS SINGLE, z1 AS SINGLE
DIM x2 AS SINGLE, y2 AS SINGLE, z2 AS SINGLE
DIM x3 AS SINGLE, y3 AS SINGLE
DIM x4 AS SINGLE, y4 AS SINGLE
DIM Face AS QD3DFACE
DIM pi AS SINGLE: pi = 3.14159265359
DIM pi2 AS SINGLE: pi2 = 6.2831853072
WITH QD3DPrimitive
.xc = .DrawCenter.x
.yc = .DrawCenter.y
.zc = .DrawCenter.z
theStep = pi/SQR(NumFaces)
theStep2 = 2* TheStep
FOR Phi = 0 TO pi STEP TheStep
FOR Theta = 0 TO pi2 STEP TheStep2
DXScreen.CreateFace(Face)
y1 = SIN(Phi) * COS(Theta)
x1 = SIN(Phi) * SIN(Theta)
z1 = COS(Phi)
y2 = SIN(Phi) * COS(Theta + TheStep2)
x2 = SIN(Phi) * SIN(Theta + TheStep2)
z2 = COS(Phi + TheStep)
y3 = SIN(Phi + TheStep) * COS(Theta + TheStep2)
x3 = SIN(Phi + TheStep) * SIN(Theta + TheStep2)
y4 = SIN(Phi + TheStep) * COS(Theta)
x4 = SIN(Phi + TheStep) * SIN(Theta)
IF .ViewFromOutside = False THEN
Face.AddVertex(x4 + .xc, y4 + .yc, z2 + .zc)
Face.AddVertex(x3 + .xc, y3 + .yc, z2 + .zc)
Face.AddVertex(x2 + .xc, y2 + .yc, z1 + .zc)
Face.AddVertex(x1 + .xc, y1 + .yc, z1 + .zc)
ELSE
Face.AddVertex(x1 + .xc, y1 + .yc, z1 + .zc)
Face.AddVertex(x2 + .xc, y2 + .yc, z1 + .zc)
Face.AddVertex(x3 + .xc, y3 + .yc, z2 + .zc)
Face.AddVertex(x4 + .xc, y4 + .yc, z2 + .zc)
END IF
.Mesh.AddFace(Face)
NEXT Theta
NEXT Phi
.Visible = True
END WITH
END SUB
SUB MakeCylinder(DXScreen AS QDXSCREEN, NumFaces AS INTEGER)
DIM Theta AS SINGLE
DIM Theta2 AS SINGLE
DIM TheStep AS SINGLE
DIM x AS SINGLE, y AS SINGLE, z AS SINGLE
DIM x2 AS SINGLE, y2 AS SINGLE, z2 AS SINGLE
DIM Face AS QD3DFACE
DIM pi2 AS SINGLE: pi2 = 6.2831853072
WITH QD3DPrimitive
.xc = .DrawCenter.x
.yc = .DrawCenter.y
.zc = .DrawCenter.z
y = 1.0
y2 = -1.0
TheStep = pi2/NumFaces
FOR Theta = 0.0 TO pi2 STEP TheStep
DXScreen.CreateFace(Face)
Theta2 = Theta + TheStep
x = COS(Theta): z = SIN(Theta)
x2 = COS(Theta2): z2 = SIN(Theta2)
IF .ViewFromOutside = False THEN
Face.AddVertex(x + .xc, y2 + .yc, z + .zc)
Face.AddVertex(x2 + .xc, y2 + .yc, z2 + .zc)
Face.AddVertex(x2 + .xc, y + .yc, z2 + .zc)
Face.AddVertex(x + .xc, y + .yc, z + .zc)
ELSE
Face.AddVertex(x + .xc, y + .yc, z + .zc)
Face.AddVertex(x2 + .xc, y + .yc, z2 + .zc)
Face.AddVertex(x2 + .xc, y2 + .yc, z2 + .zc)
Face.AddVertex(x + .xc, y2 + .yc, z + .zc)
END IF
.Mesh.AddFace(Face)
NEXT Theta
.Visible = True
END WITH
END SUB
SUB MakeCone(DXScreen AS QDXSCREEN, NumFaces AS INTEGER)
DIM Theta AS SINGLE
DIM Theta2 AS SINGLE
DIM TheStep AS SINGLE
DIM x AS SINGLE, y AS SINGLE, z AS SINGLE
DIM x2 AS SINGLE, y2 AS SINGLE, z2 AS SINGLE
DIM Face AS QD3DFACE
DIM pi2 AS SINGLE: pi2 = 6.2831853072
WITH QD3DPrimitive
.xc = .DrawCenter.x
.yc = .DrawCenter.y
.zc = .DrawCenter.z
y = 1.0
y2 = -1.0
TheStep = pi2/NumFaces
FOR Theta = 0.0 TO pi2 STEP TheStep
DXScreen.CreateFace(Face)
Theta2 = Theta + TheStep
x = COS(Theta): z = SIN(Theta)
x2 = COS(Theta2): z2 = SIN(Theta2)
IF .ViewFromOutside = False THEN
Face.AddVertex(x + .xc, y2 + .yc, z + .zc)
Face.AddVertex(x2 + .xc, y2 + .yc, z2 + .zc)
Face.AddVertex(0.0+ .xc, y + .yc, 0.0 + .zc)
ELSE
Face.AddVertex(0.0+ .xc, y + .yc, 0.0 + .zc)
Face.AddVertex(x2 + .xc, y2 + .yc, z2 + .zc)
Face.AddVertex(x + .xc, y2 + .yc, z + .zc)
END IF
.Mesh.AddFace(Face)
NEXT Theta
.Visible = True
END WITH
END SUB
CONSTRUCTOR
New()
END CONSTRUCTOR
END TYPE
CONST MaxD3DClones = 100
TYPE QD3DCloneMesh EXTENDS QOBJECT
PRIVATE:
Initialized AS INTEGER
RangeX AS SINGLE
RangeZ AS SINGLE
PUBLIC:
Visible AS INTEGER PROPERTY SET Set_Visible
CloneNum AS INTEGER PROPERTY SET Set_CloneNum
File AS STRING
Mesh AS QD3DMESHBUILDER
Frame(MaxD3DClones) AS QD3DFRAME
Range AS QRECT
RandPos AS INTEGER PROPERTY SET Set_RandPos
POS(MaxD3DClones) AS QD3DVECTOR
Orient(MaxD3DClones) AS QD3DOrientVector
RandScale AS INTEGER PROPERTY SET Set_RandScale
Scale AS QD3DVECTOR
TextureFile AS STRING
TexOriginX AS SINGLE
TexOriginY AS SINGLE
TexOriginZ AS SINGLE
TexOriginU AS SINGLE
TexOriginV AS SINGLE
TexScaleU AS SINGLE
TexScaleV AS SINGLE
TexWrapType AS LONG
COLOR AS QD3DRGBA
PROPERTY SET Set_Visible(VisibleValue AS INTEGER)
DIM i AS INTEGER
This.Visible = VisibleValue
IF VisibleValue = 1 THEN
IF This.Initialized THEN
FOR i = 1 TO This.CloneNum
This.Frame(i).AddVisual(This.Mesh)
NEXT i
ELSE
SHOWMESSAGE "Initialize CloneObject first"
END IF
ELSE
IF This.Initialized THEN
FOR i = 1 TO This.CloneNum
This.Frame(i).DeleteVisual(This.Mesh)
NEXT i
END IF
END IF
END PROPERTY
PROPERTY SET Set_CloneNum(TheCloneNum AS INTEGER)
IF TheCloneNum < = MaxD3DClones THEN
This.CloneNum = TheCloneNum
END IF
END PROPERTY
PROPERTY SET Set_RandPos(RandPosValue AS INTEGER)
DIM i AS INTEGER
This.RandPos = RandPosValue
IF RandPosValue <> 0 THEN
WITH This
.RangeX = .Range.Right - .Range.Left
.RangeZ = .Range.Top - .Range.Bottom
FOR i = 1 TO .CloneNum
This.POS(i).x = RND * .RangeX + (.Range.Left/1)
This.POS(i).y = RND
This.POS(i).z = RND * .RangeZ + (.Range.Bottom/1)
NEXT i
END WITH
END IF
END PROPERTY
PROPERTY SET Set_RandScale(RandScaleValue AS INTEGER)
WITH This
.RandScale = RandScaleValue
IF RandScaleValue <> 0 THEN
.Scale.x = RND
.Scale.y = RND
.Scale.z = .Scale.x
ELSE
.Scale.x = 1.0!
.Scale.y = 1.0!
.Scale.z = 1.0!
END IF
END WITH
END PROPERTY
SUB Init(DXscreen AS QDXSCREEN)
DIM i AS INTEGER
IF This.Initialized THEN
FOR i = 1 TO This.CloneNum
This.Frame(i).DeleteVisual(This.Mesh)
NEXT i
END IF
DXScreen.CreateMeshbuilder(This.Mesh)
IF This.File <>"" THEN This.Mesh.Load(This.File)
This.Mesh.Scale(This.Scale.x, This.Scale.y, This.Scale.z)
FOR i = 1 TO This.CloneNum
DXScreen.CreateFrame(This.Frame(i))
This.Frame(i).AddVisual(This.Mesh)
This.Frame(i).SetPosition(This.POS(i).x, This.POS(i).y, This.POS(i).z)
NEXT i
This.Initialized = True
END SUB
FUNCTION New() AS INTEGER
DIM i AS INTEGER
WITH QD3DCloneMesh
.Initialized = False
.Visible = True
.File = null
.CloneNum = 0
.RandPos = False
.Range.Left = -1
.Range.Top = 1
.Range.Right = 1
.Range.Bottom = -1
.RangeX = 2
.RangeZ = 2
.RandScale = False
.Scale.x = 1.0!
.Scale.y = 1.0!
.Scale.z = 1.0!
FOR i = 0 TO MaxD3DClones
.POS(i).x = 0.0!
.POS(i).y = 0.0!
.POS(i).z = 0.0!
.Orient(i).x = 0.0!
.Orient(i).y = 1.0!
.Orient(i).z = 1.0!
.Orient(i).dvx = 0.0!
.Orient(i).dvy = 1.0!
.Orient(i).dvz = 0.0!
NEXT i
.TextureFile = null
.TexOriginX = 0.0!
.TexOriginY = 0.0!
.TexOriginZ = 0.0!
.TexOriginU = 0.0!
.TexOriginV = 0.0!
.TexScaleU = 0.0!
.TexScaleV = 0.0!
.TexWrapType = D3DRMWRAP_SPHERE
.COLOR.R = 0.0!
.COLOR.G = 0.0!
.COLOR.B = 0.0!
.COLOR.A = 0.0!
END WITH
END FUNCTION
CONSTRUCTOR
New
END CONSTRUCTOR
END TYPE
$UNDEF null
$TYPECHECK OFF
|
|