CreateMirror() problem?

Blitz3D Forums/Blitz3D Programming/CreateMirror() problem?

I think there is weird thing about CreateMirror().
An object which is under mirror plane also appear above the mirror. Anyone can help? Here is the code:

Graphics3D 800,600,32,2
SetBuffer BackBuffer()

;Lights
light01=CreateLight()
PositionEntity light01,15,20,15

;Plane
plane=CreatePlane()
EntityColor plane, 0, 30, 255
EntityAlpha plane, 0.8

;Mirror
mirror = CreateMirror();

;Camera
cam=CreateCamera()
PositionEntity cam,0,5,-15
RotateEntity cam,10,0,0

;Cube
cube=CreateCube()
ScaleEntity cube,2,2,2

cube2 = CreateCube() ; no PhysX object
PositionEntity cube2, -10, 3, 0
EntityColor cube2, 255, 0, 0

cube3 = CreateCube() ; no PhysX object
PositionEntity cube3, 10, -3, 0
EntityColor cube3, 255, 0, 0


sp = CreateSphere ()
EntityColor sp, 255, 0, 0


Repeat ;Main Loop

If (KeyDown(31)) ShowEntity mirror ; press S to show mirror
If (KeyDown(35)) HideEntity mirror ; press H to hide mirror

time=MilliSecs ()

UpdateWorld()
RenderWorld()


Text(0, 0,"press S to show mirror")
Text(0,20,"press H to hide mirror")

Flip

Until KeyHit(1)

End

Nice example. And yes, I believe that is 'normal'. Objects above the mirror will appear under it, and objects underneath it will also appear above it. The only way I know to deal with it, is avoiding objects from getting under the mirror. Or render a second camera onto an object, and use that as a mirror, however that method can be quite slow.

Yes, this is a known 'feature' of Blitz mirrors.

I also found that using a mirror caused my sky-dome texture to break up, but that may just be my card/drivers.

I think the only time I've ssen this used succesfully is with a tiled floor (shiny marble look) where there was absolutely nothing underneath.

Actually, why don't you define a second camera, and use that as a mirror, it's absolutely perfect for what you might be looking for, and it doesn't have these issues. All you have to do is grab the image from the second camera and use that as a texture for your mirror. How does it sound? There is an example of this in the code archive, but I enhanced it some bit. Let me find my version...

; fakemirrors 

width=800
height=600
fovsphere#=65.0
fovmirror#=70.0
texsize=512
testfl=1


Graphics3D width,height 

SetBuffer BackBuffer() 

; create textures
tex=CreateTexture( texsize,texsize,48+256)
tex2=CreateTexture( texsize,texsize,48+256)

;setup cube texture
SetBuffer TextureBuffer(tex2) 
ClsColor 255,255,255 
Cls
For q=1 To 200
Color Rnd(255),Rnd(255),Rnd(255)
Rect Rnd(640),Rnd(480),Rnd(32),Rnd(32)
Next
SetBuffer BackBuffer() 

; brushes
brush1=CreateBrush() 
BrushTexture brush1,tex 
;BrushShininess brush1,1 
BrushFX brush1,1

brush2=CreateBrush() 
BrushTexture brush2,tex2

brush3=CreateBrush(2550,0,0) 



; objects

sphere_object=CreateSphere()
sphere_pivot=CreatePivot(sphere_object)
sphere_camera=CreateCamera(sphere_object) 
light=CreateLight() 

cube2=CreateCube()
ScaleMesh cube2,200,200,200
FlipMesh cube2
PaintMesh cube2,brush2


mirror_object=CreateMesh() 
surf=CreateSurface(mirror_object) 
v0=AddVertex(surf,-5, 5, 0, 1.0, 0.0)  ; upper left 
v1=AddVertex(surf, 5, 5, 0, 0.0, 0.0)   ; upper right 
v2=AddVertex(surf, 5,-5, 0, 0.0, 1.0)   ; lower right 
v3=AddVertex(surf,-5,-5, 0, 1.0, 1.0)  ; lower left 
t0=AddTriangle(surf,v0,v1,v2) ; triangle 1 
t1=AddTriangle(surf,v2,v3,v0) ; triangle 2 

mirror_pivot_left=CreatePivot(mirror_object)
mirror_pivot_right=CreatePivot(mirror_object)
PositionEntity mirror_pivot_left,-10,10,0 
PositionEntity mirror_pivot_right,10,10,0 

mirror_camera=CreateCamera(mirror_object)

; paint objects
PaintMesh mirror_object,brush1 
PaintMesh sphere_object,brush3 


; posititon and orient objects
PositionEntity mirror_object,0,0,100 
RotateEntity light,45,0,0 
RotateEntity mirror_camera,0.0,180.0,0.0 


While Not KeyDown(1) 

Gosub movesphere
Gosub rmirror

Cls
HideEntity(mirror_camera)
ShowEntity(sphere_camera)

CameraZoom sphere_camera,(1.0 / Tan(fovsphere#/2.0))
CameraClsColor sphere_camera,0,0,0
RenderWorld 

frames=frames+1
If fpstimer < (MilliSecs() - 1000)
	fps=frames
	frames=0
	fpstimer=MilliSecs()
EndIf
Text 10,10, fps
Text 10,30, fovmirror#
Text 10,50, mirror_distance#


Flip 

Wend 

End 


.movesphere
	If KeyDown( 203) Then TurnEntity sphere_object,0,0.5,0
	If KeyDown( 205 ) Then TurnEntity sphere_object,0,-0.5,0
	If KeyDown( 200 ) Then MoveEntity sphere_object,0,0,0.5
	If KeyDown( 208 ) Then MoveEntity sphere_object,0,0,-0.5
	If KeyDown( 30 ) Then MoveEntity sphere_object,0,0.5,0
	If KeyDown( 44 ) Then MoveEntity sphere_object,0,-0.5,0
	If KeyHit(17) Then wire= Not wire

	WireFrame wire
Return


.rmirror
    HideEntity(sphere_camera)
    ShowEntity(mirror_camera)

	CameraClsColor mirror_camera,0,0,255
	PointEntity(sphere_pivot, mirror_object) 

        mirror_distance#=Abs(EntityDistance ( sphere_object, mirror_object))
        PositionEntity mirror_camera,0.0,0.0,mirror_distance#
	RotateEntity mirror_camera,EntityPitch(mirror_object)+(EntityPitch(sphere_pivot,1)*1.0),EntityYaw(mirror_object)+180+(EntityYaw(sphere_pivot,1)*-1.0),EntityRoll(mirror_object) 

	PointEntity(sphere_pivot, mirror_pivot_left) 
	fov1#=EntityYaw(sphere_pivot);*1.75
	PointEntity(sphere_pivot, mirror_pivot_right) 
	fov2#=EntityYaw(sphere_pivot);*1.75

	fovmirror#=Abs(fov2#-fov1#)

	CameraZoom mirror_camera,(1.0 / Tan(fovmirror#/2.0))

	Cls
	RenderWorld 
    CopyRect (width/2)-(texsize/2),(height/2)-(texsize/2),texsize,texsize,0,0,0,TextureBuffer(tex)
Return