$TYPECHECK ON
$INCLUDE "RapidQ_D3D.INC"
DECLARE SUB DXInitialize(Sender AS QDXSCREEN)
DECLARE SUB DXInitializeSurface(Sender AS QDXSCREEN)
DECLARE SUB DXTimerExpired
DECLARE SUB ToggleRotation (Button AS INTEGER, X AS INTEGER, Y AS INTEGER)
DIM DXTimer AS QDXTIMER
DXTimer.Enabled = 1
DXTimer.Interval = 0
DXTimer.Activeonly = 0
DXTimer.OnTimer = DXTimerExpired
DIM MeshFrame AS QD3DFRAME
DIM LightFrame AS QD3DFRAME
DIM MeshBuilder AS QD3DMESHBUILDER
DIM i AS SINGLE
DIM RotAngl AS SINGLE : RotAngl = 0.03
DIM RotateIt AS SINGLE: RotateIt = 0
DIM TransDir AS SINGLE: TransDir= 1
RANDOMIZE
CREATE Form AS QFORM
CAPTION = "Direct 3D Example - click or move mouse"
Width = 640
Height = 480
Center
CREATE DXScreen AS QDXSCREEN
Init(640,480)
Align = 5
BitCount = 16
Use3D = 1
UseHardware = 1
OnInitialize = DXInitialize
OnInitializeSurface = DXInitializeSurface
OnMouseDown = ToggleRotation
END CREATE
SHOWMODAL
END CREATE
SUB DXInitialize(Sender AS QDXSCREEN)
DIM Ambient AS QD3DLIGHT
DIM Light AS QD3DLIGHT
DIM Face AS QD3DFACE
DIM Face2 AS QD3DFACE
DIM x AS DOUBLE, y AS DOUBLE, z AS DOUBLE
DXScreen.CreateFrame(MeshFrame)
DXScreen.CreateFrame(LightFrame)
DXScreen.CreateMeshBuilder(MeshBuilder)
DXScreen.CreateLightRGB(D3DRMLIGHT_AMBIENT, 0.2, 0.2, 0.5, Ambient)
DXScreen.AddLight(Ambient)
DXScreen.CreateLightRGB(D3DRMLIGHT_POINT, 0.8, 0.8, 0.2, Light)
DXScreen.AddLight(Light)
LightFrame.AddLight(Light)
LightFrame.SetPosition(0, 2, -1)
DIM openDialog AS QOPENDIALOG
openDialog.CAPTION = "open a direct x model"
openDialog.filter = "*.x (X models)|*.x"
IF openDialog.EXECUTE THEN
meshBuilder.load(openDialog.filename)
MeshBuilder.Scale(0.025, 0.025, 0.025)
MeshBuilder.SetQuality(D3DRMRENDER_GOURAUD)
MeshFrame.AddVisual(MeshBuilder)
MeshFrame.SetRotation(0, 0, 0,RotAngl)
DXScreen.SetCameraPosition(8, 2, 0)
DXScreen.CameraLookAt(MeshFrame, D3DRMCONSTRAIN_Z)
ELSE
Application.Terminate
END IF
END SUB
SUB DXInitializeSurface(Sender AS QDXSCREEN)
DXScreen.SetRenderMode(D3DRMRENDERMODE_BLENDEDTRANSPARENCY D3DRMRENDERMODE_BLENDEDTRANSPARENCY OR D3DRMRENDERMODE_DISABLESORTEDALPHAZWRITE OR D3DRMRENDERMODE_VIEWDEPENDENTSPECULAR)
END SUB
SUB DXTimerExpired
i = i +.01 * TransDir
IF ABS(i) > 2 THEN TransDir = TransDir * -1
DXScreen.SetCameraPosition(8, 2, i - 1)
LightFrame.SetPosition(Screen.MOUSEX/200, Screen.MOUSEY/200, Screen.MOUSEY/200)
DXScreen.ForceUpdate(0,0,50,40)
DXScreen.Move(1)
DXScreen.Render
DXScreen.TextOut(10,10,"FPS: "+STR$(DXTimer.FrameRate), &HFFFFFF, -1)
DXScreen.Flip
END SUB
SUB ToggleRotation (Button AS INTEGER, X AS INTEGER, Y AS INTEGER)
IF Button = 0 THEN
MeshBuilder.Scale(0.5, 0.5, 0.5)
END IF
IF Button = 1 THEN
MeshBuilder.Scale(2, 2, 2)
END IF
IF RotateIt THEN
MeshFrame.SetRotation(0, 0, 0, 0)
RotateIt= 0
ELSE
MeshFrame.SetRotation(0, 0, 0, RotAngl)
LightFrame.SetPosition(-1, 2, 0)
RotateIt = 1
END IF
END SUB
|
|