[B3D] 1:1 2D-Camera in 3D
Übersicht

BIG BUGBetreff: [B3D] 1:1 2D-Camera in 3D |
![]() Antworten mit Zitat ![]() |
|
---|---|---|
Ist jetzt nix großartiges, aber alle Jahre wieder ist es ganz nützlich eine 1:1-Zuordnung von 3D-Koordinaten zu 2D-Pixel-Koordinaten zu haben, ohne sich gleich eine ganze Library includieren zu müssen.
Daher hier eine simple Funktion, welche eine 2D-Kamera erzeugt. Die 3D X & Y Koordinaten entsprechen hierbei exakt den Pixeln auf dem Bildschirm. Möchte man diese Variante mit 3D kombinieren(z.B. als HUD oder Menü) kann man zuerst seine 3D-Kamera rendern, diese dann deaktivieren und dann die 2D-Kamera darüber rendern(oder gleich eine Library benutzen) Mit CameraViewPort kann man die 2D-Kamera auch beschränken. Code: [AUSKLAPPEN] ;by Robert Hierl (BIG BUG) 10.03.2009
Graphics3D 640,480,0,2 SetBuffer BackBuffer() ;create 2D camera where x/y coordinates match pixel coordinates cam2D = Create2DCamera(0, 0) ;create rect mesh mesh = Create3DRect(GraphicsWidth()/2-50, GraphicsHeight()/2-50, 100, 100) EntityColor mesh, 150, 150, 200 While Not KeyHit(1) Cls RenderWorld Color 255,0,0 If KeyHit(57) Then switch = Not switch ;space key If switch Then Rect GraphicsWidth()/2-50, GraphicsHeight()/2-50, 100, 100, 0 Flip Wend ;create 2D camera where x/y coordinates match exact pixel coordinates Function Create2DCamera( originX# = 0, originY# = 0 ) cam2d = CreateCamera() CameraProjMode cam2D, 2 CameraClsMode cam2D, 0, 1 CameraZoom cam2D, 2.0 / GraphicsWidth() PositionEntity cam2D, GraphicsWidth()/2-originX#, GraphicsHeight()/2-OriginY#, -10 ScaleEntity cam2D, 1,-1,1 End Function ;create mesh which represents simple rectangle (quad) Function Create3DRect( posX#, posY#, width#, height# ) Local mesh = CreateMesh() Local surf = CreateSurface(mesh) AddVertex(surf, posX# , posY# , 0) AddVertex(surf, posX#+width#, posY# , 0) AddVertex(surf, posX# , posY#+height#, 0) AddVertex(surf, posX#+width#, posY#+height#, 0) AddTriangle surf, 0, 1, 2 AddTriangle surf, 1, 3, 2 EntityFX mesh, 1 Return mesh End Function |
||
B3D-Exporter für Cinema4D!(V1.4)
MD2-Exporter für Cinema4D!(final) |
Übersicht


Powered by phpBB © 2001 - 2006, phpBB Group