Hilfe

SetCubeFace

B3D

Aufruf

SetCubeFace textur%, seite%

Parameter

textur% Textur-Identität
seite% 0=links (neg x)
1=vorne (pos z)
2=rechts (pos x)
3=hinten (neg z)
4=oben (pos y)
5=unten (neg y)


Rückgabewert

-


Beschreibung

Diese Funktion wird benutzt, um direkt in Cubemap zu zeichnen (für Echtzeitreflexionen). Ansonsten kann eine vorbearbeitete, statische Textur mit LoadTexture und Flag 128 geladen werden.

Funktionsweise: Cubemap besteht in BlitzBasic aus 6 Bildern - für jede Würfelseite ein Bild. Die Größe muss 32,64,128 usw. sein. Diese Grafiken werden von BlitzBasic automatisch verwaltet - mit einem Unterschied zu normalen Texturen: Man hat immer nur Zugriff auf eine Würfelseite. Mit diesem Befehl kann man ganz einfach die Würfelseite auswählen. Nur auf diese Seite wirkt sich Grafikänderung aus.

Textur, die mit LoadTexture geladen wird, muss 6 horizontal angeordnete Bilder enthalten - die dann autom. zu den Seiten 0-5 zugewiesen werden.

So kannst du Echtzeitspiegelung machen: Render 6 3D-Grafiken und kopiere diese jeweils auf eine Würfelseite. Dies ist jedoch etwas langsam - deaktiviere darum Mip-Mapping oder rendere 1 Würfelseite pro Frame. Zusätzlich kann Texture-Flag 256 eingeschaltet werden.

Während ein Buffer gesperrt ist, darf dieser Befehl nicht ausgeführt werden!


Beispiel

Standardbeispiel:

width = 640
height = 480
depth = 0
mode = 0

Graphics3D width, height, depth, mode
SetBuffer BackBuffer()

If GfxDriverCaps3D()<110 Then RuntimeError "Sorry, your GRAPHICS card does NOT support cubic environemnt maps."

cam = CreateCamera()
PositionEntity cam, 0, 10, - 10

cube_cam = CreateCamera()

light = CreateLight()
RotateEntity light, 90, 0, 0

teapot = LoadMesh("media/teapot.x")
ScaleEntity teapot, 3, 3, 3
PositionEntity teapot, 0, 10, 0

ground = CreatePlane()
EntityColor ground, 168, 133, 55
ground_tex = LoadTexture("media/sand.bmp")
ScaleTexture ground_tex, 10, 10
EntityTexture ground, ground_tex

sky = CreateSphere(24)
ScaleEntity sky, 500, 500, 500
FlipMesh sky
EntityFX sky, 1
sky_tex = LoadTexture("media/sky.bmp")
EntityTexture sky, sky_tex

cactus = LoadMesh("media/cactus2.x")
FitMesh cactus, - 5, 0, - 5, 2, 6, .5

camel = LoadMesh("media/camel.x")
FitMesh camel, 5, 0, - 5, 6, 5, 4

ufo_piv = CreatePivot()
PositionEntity ufo_piv, 0, 15, 0
ufo = LoadMesh("media/green_ufo.x", ufo_piv)
PositionEntity ufo, 0, 0, 10

tex = CreateTexture(256, 256, 1 + 128 + 256)

EntityTexture teapot, tex


While Not KeyDown(1)
   mxs# = mxs# + (MouseXSpeed() / 5.0)
   mys# = mys# + (MouseYSpeed() / 5.0)

   RotateEntity cam, mys#, - mxs#, 0
   MoveMouse width / 2, height / 2

   If KeyDown(200) = True Then MoveEntity cam, 0, 0, .2
   If KeyDown(208) = True Then MoveEntity cam, 0, 0, - .2
   If KeyDown(205) = True Then MoveEntity cam, .2, 0, 0
   If KeyDown(203) = True Then MoveEntity cam, - .2, 0, 0

   TurnEntity ufo_piv, 0, 2, 0
   UpdateCubemap(tex, cube_cam, teapot)
   RenderWorld
   Text 0, 0, "Use mouse TO look around"
   Text 0, 20, "Use cursor keys TO change camera position"
   Flip
Wend


Function UpdateCubemap(tex, camera, entity)
   tex_sz = TextureWidth(tex)
   ShowEntity camera
   HideEntity entity
   PositionEntity camera, EntityX#(entity), EntityY#(entity), EntityZ#(entity)
   CameraClsMode camera, False, True
   CameraViewport camera, 0, 0, tex_sz, tex_sz

   SetCubeFace tex, 0
   RotateEntity camera, 0, 90, 0
   RenderWorld
   CopyRect 0, 0, tex_sz, tex_sz, 0, 0, BackBuffer(), TextureBuffer(tex)

   SetCubeFace tex, 1
   RotateEntity camera, 0, 0, 0
   RenderWorld
   CopyRect 0, 0, tex_sz, tex_sz, 0, 0, BackBuffer(), TextureBuffer(tex)

   SetCubeFace tex, 2
   RotateEntity camera, 0, - 90, 0
   RenderWorld
   CopyRect 0, 0, tex_sz, tex_sz, 0, 0, BackBuffer(), TextureBuffer(tex)

   SetCubeFace tex, 3
   RotateEntity camera, 0, 180, 0
   RenderWorld
   CopyRect 0, 0, tex_sz, tex_sz, 0, 0, BackBuffer(), TextureBuffer(tex)

   SetCubeFace tex, 4
   RotateEntity camera, - 90, 0, 0
   RenderWorld
   CopyRect 0, 0, tex_sz, tex_sz, 0, 0, BackBuffer(), TextureBuffer(tex)

   SetCubeFace tex, 5
   RotateEntity camera, 90, 0, 0
   RenderWorld
   CopyRect 0, 0, tex_sz, tex_sz, 0, 0, BackBuffer(), TextureBuffer(tex)

   ShowEntity entity
   HideEntity camera
End Function


Siehe auch

SetCubeMode

Übersicht 3D Grafik Texturen