Camera as mirror?
Blitz3D Forums/Blitz3D Programming/Camera as mirror?
| ||
How do I create a rear-view mirror using camera 2? I think that the camera view should be flipped vertically.camera01=CreateCamera() camera02=CreateCamera() CameraViewport camera01,0,0,1024,768 CameraViewport camera02,384,0,256,128 CameraClsColor camera01,128,191,255 CameraClsColor camera02,128,191,255 |
| ||
camera01=CreateCamera() camera02=CreateCamera(camera02) TurnEntity camera02,0,180,0 HideEntity camera02 in the main loop : ; disable parent, to hide camera01 without the 02 entityparent camera02,0 hideentity camera01 ShowEntity camera02 renderworld => Copyrect from the camera02 to a texturebuffer, and apply the texture to a mesh that have UV coord form 1 to 0 instead of 0 to 1 . entityparent camera02,camera01 Hideentity camera02 then make your renderworld:flip etc... Notice your rear view will be view with a quad that you'll parent to the camera01 Something like this : |
| ||
instead of using show and hide for the cameras use CameraProjMode |
| ||
Oh i forgot it, you're right ! |
| ||
How do I create a mirror that's 256 units by 128 units centered on the top edge of the screen? How do I remove the code that allows me to move around with the mouse? |
| ||
use cameraviewport(camera,startingx,startingy,endingx,endingy) then, as long as your camera is pointed right it, and your using the right projmode it should work fine. |
| ||
How do I remove the code that allows me to move around with the mouse? mmm...maybe you should learn a little more Blitz3D before purchasing other exemple. You seem to ask something, that you don't understand mains functions . => however, comment the line "CAM_Maj_Cam (Piv,cam,dt,0)" |
| ||
Here's the code so far:Global speed#=0 Global steer#=0 Global gear%=0 Global stick%=0 Global gearstring$="Neutral" Graphics3D 1024,768,32,1 SetBuffer BackBuffer() plane=CreatePlane() EntityColor plane,63,63,63 tex1=LoadTexture("buildingwall03.tga") tex2=LoadTexture("concrete2.tga") building=CreateCube() ScaleMesh building,25,25,25 EntityTexture building,tex1 PositionMesh building,0,25,0 HideEntity building sidewalk=CreateCube() ScaleMesh sidewalk,35,1,35 EntityTexture sidewalk,tex2 PositionMesh sidewalk,0,1,0 HideEntity sidewalk For x = 0 To 74 For y = 0 To 74 cube01=CopyEntity(building) cube02=CopyEntity(sidewalk) PositionEntity cube01,y * 100,1,x * 100 PositionEntity cube02,y * 100,-1,x * 100 Next Next world=CreatePivot() pivot=CreatePivot(world) camera01=CreateCamera(pivot) CameraClsColor camera01,128,191,255 CameraViewport camera01,0,0,1024,768 MoveEntity camera01,50,5,0 RearQuad=CreateMesh(camera01) s=CreateSurface(RearQuad) v0=AddVertex(s,-0.25,1.00,1.01,+1,+0) v1=AddVertex(s,0.25,1.00,1.01,+0,+0) v2=AddVertex(s,0.25,0.50,1.01,+0,+1) v3=AddVertex(s,-0.25,0.50,1.01,+1,+1) AddTriangle s,v0,v1,v2 AddTriangle s,v0,v2,v3 RearTex=CreateTexture(256,128,1) RearBuffer=TextureBuffer(RearTex) EntityTexture RearQuad,RearTex EntityFX RearQuad,1+8 camera02=CreateCamera(camera01) CameraClsColor camera02,128,191,255 TurnEntity camera02,0,180,0 CameraProjMode camera02,0 CameraViewport camera02,0,0,256,128 light=CreateLight() RotateEntity light,0,90,0 gear=0 speed=0 If JoyType(0) Then stick=0 If JoyType(1) Then stick=1 If JoyType(2) Then stick=2 If JoyType(3) Then stick=3 While Not KeyDown(1) If JoyHit(13,stick) Then gear=gear-1:If gear<-1 Then gear=-1 If JoyHit(14,stick) Then gear=gear+1:If gear>1 Then gear=1 If gear=-1 Then gearstring="Reverse" If gear=0 Then gearstring="Neutral" If gear=1 Then gearstring="Drive" If JoyY(stick) < -0.05 If gear=1 speed=speed+0.005 If speed>2 Then speed=2 MoveEntity camera01,0,0,speed End If If gear=-1 speed=speed-0.005 If speed<-0.5 Then speed=-0.5 MoveEntity camera01,0,0,speed EndIf End If If JoyY(stick) > 0.05 speed=speed-0.01 If speed<0 Then speed=0 speed=speed*0.99 MoveEntity camera01,0,0,speed End If If JoyY(stick) > -0.05 And JoyY(stick) < 0.05 speed=speed*0.99 MoveEntity camera01,0,0,speed End If If JoyX(stick) < -0.05 And speed>0 steer=-JoyX(stick) If steer>1 Then steer=1 TurnEntity camera01,0,steer,0 End If If JoyX(stick) > 0.05 And speed>0 steer=-JoyX(stick) If steer<-1 Then steer=-1 TurnEntity camera01,0,steer,0 End If If JoyX(stick) < -0.05 And speed<0 steer=JoyX(stick) If steer<-1 Then steer=-1 TurnEntity camera01,0,steer,0 End If If JoyX(stick) > 0.05 And speed<0 steer=JoyX(stick) If steer>1 Then steer=1 TurnEntity camera01,0,steer,0 End If If JoyX(stick) > -0.05 And JoyX(stick) < 0.05 Then steer=0 EntityParent camera02,0 CameraProjMode camera01,0 CameraProjMode camera02,1 RenderWorld CopyRect 0,0,256,128,0,0,BackBuffer(),RearBuffer EntityParent camera02,Camera01 CameraProjMode camera02,0 CameraProjMode Camera01,1 UpdateWorld RenderWorld Text 0,0,"Car speed:"+speed*100 Text 0,15,"Gear:"+gearstring Flip Wend End Two problems: The mirror camera is tilted to the ground and the car stops suddenly in reverse. |