UnderwareDESIGN

PlayBASIC => Show Case => Topic started by: Kman1011 on March 22, 2009, 09:46:28 AM

Title: Some 3D screen shots
Post by: Kman1011 on March 22, 2009, 09:46:28 AM
Here are some of the screen shots from a program I am working on

I used RotateVertexListtoCamera to calc all the vertexes



mind U these are just preliminary shots using Quad polygons

In the end hopefully it will look similar to the third shot from a program I wrote a while back.


I will be back with more updates and screenshots. I don't have as much time on my hands these days..
Title: Re: Some 3D screen shots
Post by: Makeii Runoru on March 22, 2009, 10:13:06 AM
I like it. : )
I'd like to see more, and possibly an editor?
Title: Re: Some 3D screen shots
Post by: Kman1011 on March 24, 2009, 03:56:47 PM
What type editor? Map editor?

Here is a basic construct I started with to show an 3D array of cubes (with near plane grid points in white(1))

You can see the cubes at any angle using the mouse and move ahead with the up arrow key.




[pbcode]
; PROJECT : 3dCam
; AUTHOR  : Kevin Picone
; CREATED : 1/17/2006
; EDITED  : 21/02/2009
; MODIFIED: Kent Seburn
; ---------------------------------------------------------------------

  #Include "VertexObjects"

;OpenScreen 1024,768,32,2

   sw=GetScreenWidth()
   sh=GetScreenHeight()

   ProjectionX#=400
   ProjectionY#=400

   ; Init the Size of the Source and rotated Vertexs  
   Constant SrcVertSize            =12
   Constant DestVertSize         =20      

   Global Xpos#
   Global Ypos#
   Global Zpos#
   Global Map_X
   Global Map_Y
   Global Map_Z

   Type tObject
      status
      ; Object Bank
      ObjectBank
      ; Vertex Bank
      VertexBank
      ; Rotation Speeds for this object
      RotSpeedX#
      RotSpeedY#
      RotSpeedZ#
      NumberOFVerts
   EndType


   Dim Object(10) As tObject



   NumberOfVertex=10000


   Obj=1


   ; ==================================
   ; make the corner pillars   
   ; ==================================
   x=900
   z=900
   y=900
   sizex=1800
   Sizey=1800
   sizez=1800

   NewObject(0,x,y,z,SizeX,SizeY,SizeZ,100,100,100,7000)

   NewObject(1,2000,2000,2000,100,100,0,25,25,25,25)   ;wall
   
   NewObject(2,2000,2000,2000,100,0,100,25,25,25,25)    ;floor
   NewObject(3,2000,2000,2000,0,100,100,25,25,25,25)    ;Wall
   NewObject(4,2000,2100,2000,100,0,100,25,25,25,25)    ;Cieling
   NewObject(5,2000,2000,2100,100,100,0,25,25,25,25)    ;Wall

   NewObject(6,2100,2000,2000,0,100,100,25,25,25,25)    ;Wall

   ; Create Camera Object
   ; =====================================
  CameraObject=CreateVertexObject(2000,2000,2000)
  VertexObjectProjectionMode(CameraObject,1,ProjectionX#,ProjectionY#)



obj=6


; =====================================
; Create Desitnation Vertex Buffer
   ; =====================================
   DestVertexBank=NewBank(20000*DestVertSize)



   ; =======================================================
   ;  Pre-calc the shading
   ; =======================================================

   Dim ShadeBufferBuffer(20000)
   NumberOfVertexdepth#=1000
   scaler#=100/NumberOfVertexdepth#   
   col=RGB(255,255,255)
   For lp=0 To NumberOfVertexdepth#
      ShadeBufferBuffer(lp)=RGBFade(col,(NumberOfVertexdepth#-lp)*scaler#)
   Next   

   CreateCamera 1


   StartTime=Timer()+5000

Do
Wait 50
   CaptureToScene
   ClsScene
         
         ; Rotate vertex list (with XYZ rotation order)
         CameraAddress=GetBankPtr(CameraObject)

         DestVertexbufferAddress   =GetBankPtr(DestVertexBank)


         TotalNumberOFVertexs=0

         For Obj=0 To GetArrayElements(Object().tObject,1)
            If Object(obj).status=True
               If obj>0
                  col=$ffffff
               Else
                  col=$ff0000
               EndIf   
               ThisObject=Object(obj).ObjectBank
               
               ObjectAddress=GetBankPtr(ThisObject)
               SrcVertexBufferAddress=GetBankPtr(Object(obj).vertexbank)

               NumberOfVertex=object(obj).NumberOFVerts

               RotateVertexListToCamera CameraAddress,ObjectAddress,SrcVertexBufferAddress,SrcVertSize,DestVertexbufferAddress,DestVertSize,NumberOfVertex   

               Address   =DestVertexbufferAddress+8
               Do
                     z#=PeekFloat(Address)
                     If z#>10
                        CaptureDepth z#
                        DotC 400+PeekFloat(Address+4),300+PeekFloat(Address+8),col;ShadeBufferBuffer(z#)
                     EndIf
                     address=address+destVertSize
               DecLoop NumberOfVertex
            EndIf
         Next   

   DrawCamera 1

   speed#=0.1

   Control_Camera(CameraObject,20)


   If KeyPressed=False
      If ScanCode()<>0 Then KeyPressed=True
         If SpaceKey()
            DemoMOde=1-demoMOde
         EndIf
   Else
      If ScanCode()=0 Then KeyPressed=False
   EndIf

   SetCursor 0,0
   Print "Rotating Vertex Lists To Viewer/Camera"
   Print Str$(TotalNumberOFVertexs)+" Shaded Z buffered Vertex"
   Print "Fps:"+Str$(FPS())
   Print "Map X Pos:"+Str$(Map_X)
   Print "Map Y Pos:"+Str$(Map_Y)
   Print "Map Z Pos:"+Str$(Map_Z)
   Print Xpos#
   Print Ypos#
   Print Zpos#

   If Timer()<StartTime
      CenterText sw/2,sh/2,"Use Arrow Keys + Mouse"
   EndIf
   

   Sync
Loop


Function NewObject(obj,x,y,z,SizeX,SizeY,SizeZ,fieldX,fieldY,fieldz,Verts)
   Object(obj).status=True
   VertexObject=CreateVertexObject(x,y,z)
   Object(obj).ObjectBank=VertexObject
   ; create Vertex Obejct Structure
  VertexObjectRotationMode(VertexObject,Rnd(1))   ; ZYX

   Object(obj).VertexBank=Make_Random_Vertex_region(sizex,sizey,sizez,fieldX,fieldY,fieldz,Verts)
   
   object(obj).NumberOFVerts=Verts
EndFunction

Function Mesh(Z,SizeX,SizeY,divX,divY,NumberOfVertex)
      ; Create Vertex Buffers     
   VertexBank=NewBank((NumberOfVertex+1)*SrcVertSize)
   Address   =GetBankPtr(VertexBank)

   For y=0 To SizeY Step SizeY/divY
      For x=0 To SizeX Step SizeX/divX
         PokeFloat Address,Float(x)
         PokeFloat Address+4,Float(y)
         PokeFloat Address+8,Float(z)
         Address=Address+SrcVertSize
      Next x
   Next y
EndFunction VertexBank      

Function Make_Random_Vertex_region(sizex,sizey,sizez,fieldX,fieldY,fieldz,NumberOfVertex)
   ; Create Vertex Buffers     
   VertexBank=NewBank((NumberOfVertex+1)*SrcVertSize)
   Address   =GetBankPtr(VertexBank)
   For z=0 To Sizez Step fieldZ
      For y=0 To SizeY Step fieldY
         For x=0 To Sizex Step fieldX
            PokeFloat Address,Float(x)
            PokeFloat Address+4,Float(y)
            PokeFloat Address+8,Float(z)
            Address=Address+SrcVertSize
         Next X
      Next Y
   Next z
EndFunction VertexBank





Psub Control_Camera(CameraObject,camspeed#)

         W=GetScreenWidth()
         H=GetScreenHeight()
         
         x1=GetScreenXpos()         
        Y1=GetScreenYpos()         
         x2=x1+w
         y2=y1+h         
            

         MMX#=MouseMoveX()
         MMY#=MouseMoveY()
         
         x#=x1+MouseX()         
         y#=y1+MouseY()         
         

         flag=0                  
         If x#=<(x1+75) Then x#=x1+(w/2): flag=1
         If x#=>(x2-75) And flag=0 Then x#=x1+(w/2): flag=1

         If y#=<(y1+75) Then y#=y1+(h/2): flag=1
         If y#=>(y2-75) Then y#=y1+(h/2): flag=1
         
         
         If flag=1
                SetMouse x#,y#
                MMX2#=MouseMoveX()
               MMY2#=MouseMoveY()
             SetMouse x#,y#      
         EndIf
         

         camf#=0   
         camx#=WrapAngle(camx#,Mmy#*0.7)
         camy#=WrapAngle(camy#,mmx#*0.7)

         acamx#=CurveAngle(camx#,acamx#,6.2)
         acamy#=CurveAngle(camy#,acamy#,6.2)

         RotateVertexObject(CameraObject,acamx#,acamy#,0)

         If UpKey()=1 Then camf#=camf#+camspeed#
         If DownKey()=1 Then camf#=camf#-camspeed#

         If camf#<>0
            movementx#,movementy#,movementz#=CalcMovement(acamx#,acamy#,0.0,Camf#)
            X#,Y#,Z#=GetVertexObjectPosition(CameraObject)
            x#=x#+movementx#
            If x#<2000 Then x#=x#+100:Dec Map_X
            If x#>2100 Then x#=x#-100:Inc Map_X
            y#=y#+movementy#
            If y#<2000 Then y#=y#+100:Dec Map_Y
            If y#>2100 Then y#=y#-100:Inc Map_Y
            z#=z#+movementz#
            If z#<2000 Then z#=z#+100:Dec Map_Z
            If z#>2100 Then z#=z#-100:Inc Map_Z

            ; clip the camera to 20 on y axis
            ;If y#<20 Then y#=20
            PositionVertexObject(CameraObject,x#,y#,z#)
            xpos#=x#
            ypos#=y#
            ZPos#=z#
         
            ;camAZ#
         EndIf
EndPsub



Function CalcMovement(Anglex#,angley#,anglez#,Speed#)
   ` invert angles
    anglex#=360-anglex#
    angley#=WrapAngle(90,-angley#)
    anglez#=360-anglez#

   ` precalc cos+sin for rotation
     cx#=Cos(anglex#)
     sx#=Sin(anglex#)

     cy#=Cos(angley#)
     sy#=Sin(angley#)
      Zpos#=Speed#
      
      z#=(cx#*Zpos#)
      y#=(sx#*zpos#)
      ` Around Y axis
      x2#=(cY#*Z#)-(sy#*X#)
      z#=((cy#*X#)+(sy#*Z#))

EndFunction x2#,y#,z#

[/pbcode]


(1)- Near planes broken down 4 x 4 to fix problem with near Z plane clipping because no points can move behind a Z distance of zero
Title: Re: Some 3D screen shots
Post by: Makeii Runoru on March 24, 2009, 05:34:16 PM
Yeah I had that problem when working in some 3D as well with Z clipping. I still find 3D to be a lot of work, so I'll just try to master 2D design first.

And by an editor, I meant a map editor, yea. Perhaps something similar to "Build," the editor for Duke Nukem 3D levels : )
Title: Re: Some 3D screen shots
Post by: kevin on March 25, 2009, 08:31:10 AM
Kman,

     It's good to see somebody tackling something outside the norm here.   If you can get it running up to speed in just standard PB,  then it'd fly in PBFX.