Rapid-Q Documentation by William Yu (c)1999 Appendix B: QD3DWRAP

 

QD3DWRAP Component

QD3DWrap implements IDirect3DRMWrap.

QD3DWrap Properties
FieldTypeR/WDefault





QD3DWrap Methods
MethodTypeDescriptionParams




ApplySUB (M AS QD3DMesh/QD3DMeshBuilder)Apply wrap to mesh1
ApplyRelativeSUB (F AS QD3DFrame, M AS QD3DMesh/QD3DMeshBuilder)Apply wrap relative to frame
2
Use this method when the wrap type is D3DRMWRAP_CHROME, which makes "environmental
mapping" or makes objects look like they are chrome or reflect off the surface of water.
 

QD3DWrap Events
EventTypeOccurs when...Params




Note, wrapping is handled by the QDXSCREEN.CreateWrap function. The parameters are

DXScreen.createWrap(_
D3DRMWRAP_SPHERE, _            ' const defines how to do texture mapping
CenterX, CenterY, CenterZ, _   ' wrap origin of texture coordinate in the model
0, 1, 0, _                     ' the z-axis vector, determines orientation of bitmap on model
0, 0, 1, _                     'and y-axis vector orientation, numbers are -1 to +1
bmpX, bmpY, _                  'start location in the bitmap
scaleX, scaleY, Wrap)          'scale the bitmap , and put in the QD3DWrap variable


QD3DWrap Examples
'Correct running verions of the WRAP.BAS program. Shows you 
'Chrome wrapping of a 3D object. The other files should be in your
'\examples\direct3d\wrap folder. This is also known as
' "environmental wrapping," which was used to give the metal-chrome
'appearance of the robot in "Terminator2." 
$TYPECHECK ON

CONST alClient = 5

'-- Light Types
CONST D3DRMLIGHT_AMBIENT = 0
CONST D3DRMLIGHT_POINT = 1
CONST D3DRMLIGHT_SPOT = 2
CONST D3DRMLIGHT_DIRECTIONAL = 3
CONST D3DRMLIGHT_PARALLELPOINT = 4

'-- Renderer modes
CONST D3DRMRENDERMODE_BLENDEDTRANSPARENCY = 1
CONST D3DRMRENDERMODE_SORTEDTRANSPARENCY = 2
CONST D3DRMRENDERMODE_LIGHTINMODELSPACE = 8
CONST D3DRMRENDERMODE_VIEWDEPENDENTSPECULAR = 16
CONST D3DRMRENDERMODE_DISABLESORTEDALPHAZWRITE = 32

'-- Wrap Types
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 WrapType = D3DRMWRAP_CHROME '-- You can modify this

DECLARE SUB DXInitialize(Sender AS QDXScreen)
DECLARE SUB DXInitializeSurface(Sender AS QDXScreen)
DECLARE SUB DXTimerExpired

DIM DXTimer AS QDXTimer
DXTimer.Enabled = 1
DXTimer.Interval = 0
DXTimer.OnTimer = DXTimerExpired

DIM MeshFrame AS QD3DFrame
DIM Mesh AS QD3DMesh
DIM Wrap AS QD3DWrap
DIM MeshBuilder AS QD3DMeshBuilder

CREATE Form AS QForm
Caption = "Direct 3D Example"
Center
Width = 330
Height = 350
CREATE DXScreen AS QDXScreen
Init(320,240)
Align = alClient
Use3D = 1
UseHardware = 1 ''for accelerated cards 0 for old ones
OnInitialize = DXInitialize
OnInitializeSurface = DXInitializeSurface
END CREATE
ShowModal
END CREATE


SUB CreateWrap
DXScreen.CreateWrap(WrapType, 0,0,0, 0,0,1, 0,1,0, 0,0, 1,1, Wrap)
Wrap.Apply(MeshBuilder)
END SUB

SUB DXInitialize(Sender AS QDXScreen)
DIM Light AS QD3DLight, Ambient AS QD3DLight
DIM LightFrame AS QD3DFrame
DIM Texture AS QD3DTexture

IF FileExists("back2.bmp") THEN
DXScreen.LoadTexture("back.bmp", Texture)
DXScreen.SetBackgroundImage(Texture)
ELSE
ShowMessage "missing bitmap"
END IF

DXScreen.CreateFrame(LightFrame)
DXScreen.CreateFrame(MeshFrame)

DXScreen.CreateLightRGB(_
D3DRMLIGHT_DIRECTIONAL, 0.9, 0.9, 0.9, Light)
LightFrame.AddLight(Light)

DXScreen.CreateLightRGB(_
D3DRMLIGHT_AMBIENT, 0.1, 0.1, 0.1, Ambient)
DXScreen.AddLight(Ambient)

LightFrame.SetPosition(2, 0, 22)
DXScreen.SetCameraPosition(-5, 5, 0)
'numbers for CameraOrientation range from-1 to 1
DXScreen.SetCameraOrientation(0.35, -0.45, 1.0, -0.15, 1.0, 0.5)

MeshFrame.SetPosition(0, 0, 15)
MeshFrame.SetOrientation(0, 0, 1, 0, 1, 0)
'the SetRotation is a quaterion!
MeshFrame.SetRotation(0, 1, 0, 0.05) 'Angle = 0.05

DXScreen.CreateMeshBuilder(MeshBuilder)
' MeshBuilder.Load("cube.x") '-- should be in example folder
MeshBuilder.Load("egg.x") '-- egg object
MeshBuilder.Scale(2,2,2)
MeshBuilder.SetRGBA(1, 1, 1, 0.8) '-- Alpha blending!

MeshBuilder.LoadTexture("back2.bmp")
MeshFrame.AddVisual(MeshBuilder)
CreateWrap

END SUB

SUB DXInitializeSurface(Sender AS QDXScreen)
DXScreen.SetRenderMode(_
D3DRMRENDERMODE_BLENDEDTRANSPARENCY OR D3DRMRENDERMODE_SORTEDTRANSPARENCY)
END SUB

SUB DXTimerExpired
'DXScreen.Fill(0) ' Call this or
DXScreen.ForceUpdate(0,0,40,40) ' Update FPS text only
'DXScreen.Move(2) ' this is rotation by 2 times
MeshFrame.Move(1)
IF WrapType = D3DRMWRAP_CHROME THEN
Wrap.ApplyRelative(MeshFrame,MeshBuilder) 'for each frame!
END IF
DXScreen.Render
DXScreen.TextOut(_
10,10,"FPS: "+STR$(DXTimer.FrameRate), &HFFFFFF, -1)
DXScreen.Flip
END SUB


Prev Component Contents Next Component