Page 1 of 2

Sphere 3D

Posted: Sat Feb 04, 2006 12:12 pm
by Comtois

Code: Select all

;Comtois 28/03/06
;PB4.0 Beta 7

Resultat = MessageRequester("Sphere 3D","Full Screen ?",#PB_MessageRequester_YesNo)
If Resultat = #PB_MessageRequester_Yes    
  FullScreen = 1
Else           
  FullScreen = 0
EndIf

;- Initialisation
If InitEngine3D() = 0
   MessageRequester("Erreur" , "Impossible d'initialiser la 3D , vérifiez la présence de engine3D.dll", 0)
   End
ElseIf InitSprite() = 0 Or InitKeyboard() = 0
   MessageRequester("Erreur", "Impossible d'initialiser DirectX 7 Ou plus", 0)
   End
EndIf

If Fullscreen
  OpenScreen(800, 600, 32, "Sphere 3D")
Else
  OpenWindow(0, 0, 0, 800, 600, "Sphere 3D")
  OpenWindowedScreen(WindowID(0), 0, 0, 800, 600, 0, 0, 0)
EndIf

Global Angle.f,Pas.f, CameraMode.l
Global *VBuffer,*IBuffer
Global meridien.l,Parallele.l ,PasMorceau.l,Morceau.l

meridien=50
Parallele=50
Pas=0.5
PasMorceau=4
Morceau=0

Structure Vecteur
   x.f
   y.f
   z.f
EndStructure
Structure Vertex
   px.f
   py.f
   pz.f
   nx.f
   ny.f
   nz.f
   Couleur.l
   U.f
   V.f
EndStructure

Structure FTriangle
   f1.w
   f2.w
   f3.w
EndStructure

Macro CALCUL_NORMALE
   *PtrV\nx = *PtrV\px
   *PtrV\ny = *PtrV\py
   *PtrV\nz = *PtrV\pz
EndMacro

Procedure CreateMeshSphere(m,p)
   ;m = méridien
   ;p = parallèle
   ;Le rayon est égal à 1 .
   ;Recto à supprimer par la suite ,c'est juste pour la démo.
   
   If m<3 Or p<2   
      ProcedureReturn 0
   EndIf
   
   Protected Normale.Vecteur
   
   NbSommet = 2 + ((m + 1) * p)
   *VBuffer=AllocateMemory(SizeOf(Vertex) * Nbsommet)
   
   For i = 0 To m
      theta.f  = i * #PI * 2.0 / m
      ctheta.f = Cos(theta)
      stheta.f = Sin(theta)
 
      For j = 1 To p
         alpha.f  = j * #PI / (p + 1)
         calpha.f = Cos(alpha)
         salpha.f =Sin(alpha)
         *PtrV.Vertex = *VBuffer + SizeOf(Vertex) * ((i * p) + (j - 1))
         *PtrV\px = salpha * ctheta
         *PtrV\py = salpha * stheta
         *PtrV\pz = calpha
         *PtrV\u  = Theta / (2.0 * #PI)
         *PtrV\v  = alpha / #PI
         CALCUL_NORMALE
      Next j
   Next i   
   
   *PtrV.Vertex = *VBuffer + SizeOf(Vertex) * ((m + 1) * p)
   ;Pole sud
   *PtrV\px = 0
   *PtrV\py = 0   
   *PtrV\pz = -1
   *PtrV\u  = 0
   *PtrV\v  = 0
   CALCUL_NORMALE
   *PtrV + SizeOf(Vertex)
   
   ;Pole nord
   *PtrV\px = 0
   *PtrV\py = 0   
   *PtrV\pz = 1
   *PtrV\u  = 0
   *PtrV\v  = 0
   CALCUL_NORMALE
   
   ;Les facettes
   NbTriangle = 4 * m * p
   *IBuffer = AllocateMemory(SizeOf(FTriangle) * NbTriangle)
   *PtrF.FTriangle = *IBuffer
   
   For i = 0 To m - 1
      For j = 1 To p - 1
         *PtrF\f1=((i + 1) * p) + j
         *PtrF\f2=((i + 1) * p) + (j - 1)
         *PtrF\f3=(i * p) + (j - 1)
         *PtrF + SizeOf(FTriangle)
         *PtrF\f3=((i + 1) * p) + j        ;Recto
         *PtrF\f2=((i + 1) * p) + (j - 1)  ;Recto
         *PtrF\f1=(i * p) + (j - 1)        ;Recto
         *PtrF + SizeOf(FTriangle)
         *PtrF\f1=i * p + j
         *PtrF\f2=((i + 1) * p) + j
         *PtrF\f3=(i * p) + (j - 1)
         *PtrF + SizeOf(FTriangle)
         *PtrF\f3=i * p + j               ;Recto
         *PtrF\f2=((i + 1) * p) + j       ;Recto
         *PtrF\f1=(i * p) + (j - 1)       ;Recto
         *PtrF + SizeOf(FTriangle)
      Next j     
   Next i
   
   ;Les Pôles
   For i = 0 To m - 1
      *PtrF\f3=(m + 1) * p + 1
      *PtrF\f2=(i + 1) * p
      *PtrF\f1=i * p
      *PtrF + SizeOf(FTriangle)
      *PtrF\f1=(m + 1) * p + 1  ;Recto
      *PtrF\f2=(i + 1) * p      ;Recto
      *PtrF\f3=i * p            ;Recto
      *PtrF + SizeOf(FTriangle)
   Next i     
     
   For i = 0 To m - 1
      *PtrF\f3=(m + 1) * p
      *PtrF\f2=i * p + (p - 1)
      *PtrF\f1=(i + 1) * p + (p - 1)
      *PtrF + SizeOf(FTriangle)
      *PtrF\f1=(m + 1) * p               ;Recto
      *PtrF\f2=i * p + (p - 1)           ;Recto
      *PtrF\f3=(i + 1) * p + (p - 1)     ;Recto
      *PtrF + SizeOf(FTriangle)   
   Next i     

   If CreateMesh(0, 100)
      Flag = #PB_Mesh_Vertex | #PB_Mesh_Normal | #PB_Mesh_UVCoordinate | #PB_Mesh_Color
      SetMeshData(0, Flag, *VBuffer, NbSommet)
      SetMeshData(0, #PB_Mesh_Face, *IBuffer, NbTriangle)
      ProcedureReturn 1
   Else
      ProcedureReturn 0   
   EndIf
   
EndProcedure   

Procedure Morceau()
   NbTriangle = 4 * meridien * Parallele
   Morceau + PasMorceau
   If morceau >= NbTriangle
      PasMorceau = 0
      Morceau = Nbtriangle
   EndIf
   SetMeshData(0, #PB_Mesh_Face, *IBuffer, Morceau)
EndProcedure

;-Mesh
CreateMeshSphere(meridien, Parallele)

;-Texture
CreateTexture(0, 128, 128)
StartDrawing(TextureOutput(0))
   For i = 0 To 127 Step 4
      Box(0, i    , TextureWidth(0), 2, RGB(255,255,255))
      Box(0, i + 2, TextureWidth(0), 2, RGB(  0,  0,155))
   Next i
StopDrawing()

;-Material
CreateMaterial(0, TextureID(0))
RotateMaterial(0, 0.1, #PB_Material_Animated)

;-Entity
CreateEntity(0, MeshID(0), MaterialID(0))
ScaleEntity(0, 60, 60, 60)

;-Camera
CreateCamera(0, 0, 0, 100, 100)
MoveCamera(0, 0, 0, -200)
CameraLookAt(0, EntityX(0), EntityY(0), EntityZ(0))

;-Light
AmbientColor(RGB(105, 105, 105))
CreateLight(0, RGB(255, 255,  55), EntityX(0) + 150, EntityY(0)      , EntityZ(0))
CreateLight(1, RGB( 55, 255, 255), EntityX(0) - 150, EntityY(0)      , EntityZ(0))
CreateLight(2, RGB( 55,  55, 255), EntityX(0)      , EntityY(0) + 150, EntityZ(0))
CreateLight(3, RGB(255,  55, 255), EntityX(0)      , EntityY(0) - 150, EntityZ(0))

Repeat
   If fullscreen = 0
      If WindowEvent() = #PB_Event_CloseWindow
         End
      EndIf
   EndIf
   
   Angle + Pas
   RotateEntity(0, Angle, Angle,Angle)
   If PasMorceau > 0
      Morceau()
   EndIf
   If ExamineKeyboard()
      If KeyboardReleased(#PB_Key_F1)
         CameraMode = 1 - CameraMode
         CameraRenderMode(0, CameraMode)
      EndIf
   EndIf
   RenderWorld()
   FlipBuffers()
Until KeyboardPushed(#PB_Key_Escape)     

Posted: Sat Feb 04, 2006 12:24 pm
by benny
E*X*C*E*L*L*E*N*T :!: :!: :!:

Posted: Sat Feb 04, 2006 12:34 pm
by PB
Hmm, I get these two error messages:

Code: Select all

---------------------------
PureBasic0.exe - Unable To Locate Component
---------------------------
This application has failed to start because stlport_vc646.dll was not found. Re-installing the application may fix this problem. 
---------------------------
OK   
---------------------------

Code: Select all

---------------------------
Erreur
---------------------------
Impossible d'initialiser la 3D , vérifiez la présence de engine3D.dll
---------------------------
OK   
---------------------------

Posted: Sat Feb 04, 2006 12:38 pm
by Num3
You need to place this http://www.itsyskon.de/HP/Download/File ... _vc646.dll in the compilers directory ;)

Posted: Sat Feb 04, 2006 12:38 pm
by benny
@PB:

You can download the missing dll in purebasic's beta section :!:

Posted: Sat Feb 04, 2006 12:48 pm
by Dare2
Comtois,

You wear the PureBasic 3D crown.

* bows *

Posted: Sat Feb 04, 2006 12:51 pm
by PB
Well, then! :D Thanks guys (and dmoc!).

@Comtois: Are you trying to hypnotize me?

Posted: Sun Feb 05, 2006 1:13 am
by SCRJ
Cool 8)
Very nice :D

Posted: Mon Mar 20, 2006 8:40 am
by akj
On my laptop the Sphere program crashes out at line 196:
If CreateMesh(0, 100)
The error message is "Invalid memory access".
This is irrespective of whether or not I take the full screen option.

I am using VB4 Beta 7 running under Windows Me and I already have stlport_vc646.dll in the PB4 Compilers folder.

How can I overcome this problem?

Posted: Mon Mar 20, 2006 10:50 am
by Fred
Very nice effect :)

Posted: Mon Mar 20, 2006 12:23 pm
by Comtois
akj wrote:On my laptop the Sphere program crashes out at line 196:
If CreateMesh(0, 100)
The error message is "Invalid memory access".
This is irrespective of whether or not I take the full screen option.

I am using VB4 Beta 7 running under Windows Me and I already have stlport_vc646.dll in the PB4 Compilers folder.

How can I overcome this problem?
I dont know .
Here is my Ogre.log , you can compare :
12:22:18: Creating resource group General
12:22:18: Registering ResourceManager for type Material
12:22:18: Registering ResourceManager for type Mesh
12:22:18: Registering ResourceManager for type Skeleton
12:22:18: OverlayElementFactory for type Panel registered.
12:22:18: OverlayElementFactory for type BorderPanel registered.
12:22:18: OverlayElementFactory for type TextArea registered.
12:22:18: Registering ResourceManager for type Font
12:22:18: ArchiveFactory for archive type FileSystem registered.
12:22:18: ArchiveFactory for archive type Zip registered.
12:22:18: DevIL version: Developer's Image Library (DevIL) 1.6.7 Aug 15 2005
12:22:18: DevIL image formats: jpg jpe jpeg pcx png tga vda icb vst raw
12:22:18: Registering ResourceManager for type HighLevelGpuProgram
12:22:18: Direct3D7 Rendering Subsystem created.
12:22:18: ----- DirectDraw Detection Starts
12:22:18: Detected DirectDraw driver Pilote d'affichage principal
12:22:18: Detected DirectDraw driver RADEON 9800 SERIES
12:22:18: ----- DirectDraw Detection Ends
12:22:18: Particle Emitter Type 'Point' registered
12:22:18: Particle Emitter Type 'Box' registered
12:22:18: Particle Emitter Type 'Ellipsoid' registered
12:22:18: Particle Emitter Type 'Cylinder' registered
12:22:18: Particle Emitter Type 'Ring' registered
12:22:18: Particle Emitter Type 'HollowEllipsoid' registered
12:22:18: Particle Affector Type 'LinearForce' registered
12:22:18: Particle Affector Type 'ColourFader' registered
12:22:18: Particle Affector Type 'ColourFader2' registered
12:22:18: Particle Affector Type 'ColourImage' registered
12:22:18: Particle Affector Type 'ColourInterpolator' registered
12:22:18: Particle Affector Type 'Scaler' registered
12:22:18: Particle Affector Type 'Rotator' registered
12:22:18: TerrainSceneManager: Registered a new PageSource for type Heightmap
12:22:18: Registering ResourceManager for type BspLevel
12:22:18: *-*-* OGRE Initialising
12:22:18: *-*-* Version 1.0.7 (Azathoth)
12:22:19: ***************************************
*** Direct3D Subsystem Initialising ***
***************************************
12:22:19: *****************************************
12:22:19: *** Direct3D Subsystem Initialised Ok ***
12:22:19: *****************************************
12:22:19: Registering ResourceManager for type GpuProgram
12:22:19: ResourceBackgroundQueue - threading disabled
12:22:19: D3D7 : Created D3D7 Rendering Window 'PureBasic Ogre' : 800x600, 32bpp
12:22:19: Creating DirectDraw surfaces for window with dimensions:
12:22:19: FULLSCREEN w:800 h:600 bpp:32
12:22:20: Successfully created full screen rendering surface / flipping chain.
12:22:20: ----- Direct3D Detection Starts
12:22:20: Detected Direct3D Device Microsoft Direct3D RGB Software Emulation
12:22:20: Direct3D Device Capabilities:
12:22:20: Hardware Accelerated: 0
12:22:20: Mipmapping: 1
12:22:20: Bilinear Filtering: 1
12:22:20: Trilinear Filtering: 1
12:22:20: Hardware Transform & Light: 0
12:22:20: Max rendering colour depth: 32
12:22:20: Max single-pass texture layers: 8
12:22:20: Pixel fog supported: 256
12:22:20: Vertex fog supported: 128
12:22:20: This device needs a Z-Buffer
12:22:20: Detected Direct3D Device Microsoft Direct3D Hardware acceleration through Direct3D HAL
12:22:20: Direct3D Device Capabilities:
12:22:20: Hardware Accelerated: 1
12:22:20: Mipmapping: 1
12:22:20: Bilinear Filtering: 1
12:22:20: Trilinear Filtering: 1
12:22:20: Hardware Transform & Light: 0
12:22:20: Max rendering colour depth: 32
12:22:20: Max single-pass texture layers: 8
12:22:20: Pixel fog supported: 256
12:22:20: Vertex fog supported: 128
12:22:20: This device needs a Z-Buffer
12:22:20: Detected Direct3D Device Microsoft Direct3D Hardware Transform and Lighting acceleration capable device
12:22:20: Direct3D Device Capabilities:
12:22:20: Hardware Accelerated: 1
12:22:20: Mipmapping: 1
12:22:20: Bilinear Filtering: 1
12:22:20: Trilinear Filtering: 1
12:22:20: Hardware Transform & Light: 1
12:22:20: Max rendering colour depth: 32
12:22:20: Max single-pass texture layers: 8
12:22:20: Pixel fog supported: 256
12:22:20: Vertex fog supported: 128
12:22:20: This device needs a Z-Buffer
12:22:20: ----- Direct3D Detection Ends
12:22:20: Determining best 3D Device...
12:22:20: Best 3D Device is: Microsoft Direct3D Hardware Transform and Lighting acceleration capable device
12:22:20: Direct3D - Creating Z-Buffer
12:22:20: Depth-Buffer created (32-bit, 8-bit stencil)
12:22:20: Registering ResourceManager for type Texture
12:22:20: RenderSystem capabilities
12:22:20: -------------------------
12:22:20: * Hardware generation of mipmaps: no
12:22:20: * Texture blending: yes
12:22:20: * Anisotropic texture filtering: yes
12:22:20: * Dot product texture operation: yes
12:22:20: * Cube mapping: yes
12:22:20: * Hardware stencil buffer: yes
12:22:20: - Stencil depth: 8
12:22:20: - Two sided stencil support: no
12:22:20: - Wrap stencil values: yes
12:22:20: * Hardware vertex / index buffers: no
12:22:20: * Vertex programs: no
12:22:20: * Fragment programs: no
12:22:20: * Texture Compression: no
12:22:20: * Scissor Rectangle: no
12:22:20: * Hardware Occlusion Query: no
12:22:20: * User clip planes: no
12:22:20: * VET_UBYTE4 vertex element type: no
12:22:20: * Infinite far plane projection: no
12:22:20: * Hardware render-to-texture: no
12:22:20: * Floating point textures: no
12:22:20: * Non-power-of-two textures: no
12:22:20: * Volume textures: no
12:22:20: Particle Renderer Type 'billboard' registered
12:22:20: WARNING: Mesh instance 'M0' was defined as manually loaded, but no manual loader was provided. This Resource will be lost if it has to be reloaded.
12:22:20: Creating viewport on target 'PureBasic Ogre', rendering from camera 'MyCam', relative dimensions L: 0.00 T: 0.00 W: 1.00 H: 1.00 ZOrder: 0
12:22:20: Viewport for camera 'MyCam', actual dimensions L: 0 T: 0 W: 800 H: 600
12:22:20: Texture: spot_shadow_fade.png: Loading 1 faces(PF_B8G8R8,128x128x1) with 0 generated mipmaps from Image. Internal format is PF_X8R8G8B8,128x128x1.

Posted: Mon Mar 20, 2006 12:27 pm
by Comtois
New effect , change Texture and MAterial

Code: Select all

;-Texture
CreateTexture(0,128, 128)
StartDrawing(TextureOutput(0))
  For i = 0 To 127 Step 8
  Box(0,i,TextureWidth(0),1,RGB(255,255,255))
  Box(0,i+1,TextureWidth(0),1,RGB(0,0,155))
  Next i
StopDrawing()

;-Material
CreateMaterial(0,TextureID(0))
MaterialBlendingMode(0,#PB_Material_Add)
RotateMaterial(0,0.1,#PB_Material_Animated)

Posted: Mon Mar 20, 2006 1:02 pm
by Michael Vogel
Here is my Ogre.log , you can compare :
How to disable the producing of the log file?

Posted: Mon Mar 20, 2006 1:31 pm
by Vallan
I see only a black screen. (PB 4 beta 5)
is it possible that the source doesn't work on slow computers?

Posted: Mon Mar 20, 2006 2:22 pm
by Thalius
@vallan
You will need a Direct3D compatible Graphics card and the above dll in order to get results. Do you have an Ogre.log you maybe can post?