Page 1 sur 2

[4.60 beta] Démo Physique + joints

Publié : mar. 05/avr./2011 14:26
par kelebrindae
Plutôt élémentaire, mais ça permet de se faire une petite idée. Et personnellement, il le plaît bien, le nouveau moteur physique... :D

(Et si quelqu'un a trouvé comment déplacer une line3D ou comment l'attacher à d'autres objets, je suis preneur...)

[EDIT:] F1, F2, F3 pour changer de vue.

Code : Tout sélectionner

; Window size
#SCREENWIDTH = 800
#SCREENHEIGHT = 500

;- initialization
InitSprite()
InitEngine3D()
InitKeyboard()

;- Window
OpenWindow(0, 0, 0, #SCREENWIDTH, #SCREENHEIGHT, "Joint test", #PB_Window_ScreenCentered|#PB_Window_SystemMenu|#PB_Window_MinimizeGadget)
OpenWindowedScreen(WindowID(0), 0, 0, #SCREENWIDTH,#SCREENHEIGHT, 0, 0, 0,#PB_Screen_SmartSynchronization)

;-Texture
Add3DArchive(".",#PB_3DArchive_FileSystem)
CreateImage(0,128, 128) 
StartDrawing(ImageOutput(0)) 
  Box(0, 0, 128, 128, $FFFFFF)
StopDrawing()
SaveImage(0,"temp.bmp")
FreeImage(0)
LoadTexture(0,"temp.bmp")
DeleteFile("temp.bmp")

;-Material
CreateMaterial(1,TextureID(0))
MaterialAmbientColor(1,#PB_Material_AmbientColors)
CreateMaterial(2,TextureID(0))
MaterialAmbientColor(2,$FFFF00)
CreateMaterial(3,TextureID(0))
MaterialAmbientColor(3,$0077FF)
CreateMaterial(4,TextureID(0))
MaterialAmbientColor(4,$FF00FF)

;- Entities
CreatePlane(4,2,2,20,20,1,1)
sol  = CreateEntity(#PB_Any, MeshID(4), MaterialID(1))
EntityPhysicBody(sol, #PB_Entity_StaticBody)    

CreateCube(4, 1)
socle=CreateEntity(#PB_Any, MeshID(4), MaterialID(1))
ScaleEntity(socle, 10,1,10)
EntityLocate(socle, 12,8,0)
EntityPhysicBody(socle, #PB_Entity_StaticBody)   

; Mobile
CreateCube(1, 1.0)
cube=CreateEntity(#PB_Any, MeshID(1), MaterialID(2))
EntityLocate(cube,-5,9,0)
EntityPhysicBody(cube, #PB_Entity_BoxBody)
   
CreateSphere(2, 0.5)
sphere=CreateEntity(#PB_Any, MeshID(2), MaterialID(3))
EntityLocate(sphere, -5,6,0)
EntityPhysicBody(sphere, #PB_Entity_SphereBody, 2.0)

; Attache the cube and the sphere, and figure this link with a 3D line
PointJoint(cube,0,0,0,sphere,0,-3,0)
CreateLine3D(3,5,9,0,$FF0000,5,6,0,$00FF00)

; Targets
For i = 1 To 4
  temp = CreateEntity(#PB_Any, MeshID(1), MaterialID(4))
  EntityLocate(temp,0,0.5,(i*1.1)-2.8)
  EntityPhysicBody(temp, #PB_Entity_BoxBody, 1)
Next i
For i = 1 To 3
  temp = CreateEntity(#PB_Any, MeshID(1), MaterialID(4))
  EntityLocate(temp,0,1.5,(i*1.1)-2.3)
  EntityPhysicBody(temp, #PB_Entity_BoxBody, 1)
Next i
For i = 1 To 2
  temp = CreateEntity(#PB_Any, MeshID(1), MaterialID(4))
  EntityLocate(temp,0,2.5,(i*1.1)-1.8)
  EntityPhysicBody(temp, #PB_Entity_BoxBody, 1)
Next i

;- Camera
CreateCamera(0, 0, 0, 100, 100)
CameraLocate(0,0,12,20)
CameraLookAt(0,0,5,0)
  
;-Light 
AmbientColor(RGB(105,105,105)) 
CreateLight(0,RGB(160,160,255),-200,300,0) 
;CreateLight(1,RGB(255,127,0),-200,-200,200)
WorldShadows(#PB_Shadow_Additive)

;- Main loop
angle.f = 0
angle2.f = 0
Repeat
  Delay(1)
  While WindowEvent() : Wend
  
  ;- F1, F2, F3 : Change view
  If ExamineKeyboard()
    If KeyboardReleased(#PB_Key_F1)
      CameraLocate(0,-12,2.5,0)
      CameraLookAt(0,0,3,0)
    EndIf
    If KeyboardReleased(#PB_Key_F2)
      CameraLocate(0,0,12,20)
      CameraLookAt(0,0,5,0)
    EndIf
    If KeyboardReleased(#PB_Key_F3)
      CameraLocate(0,3,5,10)
      CameraLookAt(0,0,3,0)
    EndIf
    
    ;- Return : Display FPS
    If KeyboardReleased(#PB_Key_Return)
      MessageRequester("Infos","FPS = " + Str(Engine3DFrameRate(#PB_Engine3D_Average)))
    EndIf

  EndIf
  
  ; Move the cube
  angle+0.02
  angle2+0.005
  EntityLocate(cube,-5*Cos(angle),9 + 5*Sin(angle),2*Cos(angle2))
  
  ; Redraw the line3D (I don't know how to do it! So I delete/recreate it in each frame...)
  FreeEntity(3)
  CreateLine3D(3,EntityX(cube),EntityY(cube),EntityZ(cube),$FF0000,EntityX(sphere),EntityY(sphere),EntityZ(sphere),$00FF00)
  
  ; Render
  RenderWorld()
  FlipBuffers()
 
Until KeyboardPushed(#PB_Key_Escape)

End

Re: [4.60 beta] Démo Physique + joints

Publié : mar. 05/avr./2011 14:54
par djes
Ne fonctionne pas pour moi... invalid memory access read error at address 32 sur le renderworld()

Re: [4.60 beta] Démo Physique + joints

Publié : mar. 05/avr./2011 15:14
par Cool Dji
Joli !!

Re: [4.60 beta] Démo Physique + joints

Publié : mar. 05/avr./2011 15:16
par kelebrindae
@Djes:
Ah bon? :?
Essaye voir de virer tout ce qui gère la line3D, pour voir? (lignes 59,124,125)

@Cool Dji: Merci!

Re: [4.60 beta] Démo Physique + joints

Publié : mar. 05/avr./2011 15:17
par djes
Pareil! C'est bizarre, parce que les autres exemples de PB fonctionnent :/

Edit: J'ai trouvé, ça vient des ombres!

Code : Tout sélectionner

;WorldShadows(#PB_Shadow_Additive)

Re: [4.60 beta] Démo Physique + joints

Publié : mar. 05/avr./2011 15:49
par kelebrindae
Bizarre... Et en "modulative", ça plante aussi ?
=> ça justifierait bien un ch'tit rapport de bug, non ?

Re: [4.60 beta] Démo Physique + joints

Publié : mar. 05/avr./2011 16:02
par G-Rom
il manque la commande LightCastShadow(lightID, state.b)
Djes , balance ton Ogre.log stp.

Re: [4.60 beta] Démo Physique + joints

Publié : mar. 05/avr./2011 16:26
par djes
Le voilà, à noter qu'il est pareil que je commente worldshadow ou pas.
17:25:06: Creating resource group General
17:25:06: Creating resource group Internal
17:25:06: Creating resource group Autodetect
17:25:06: SceneManagerFactory for type 'DefaultSceneManager' registered.
17:25:06: Registering ResourceManager for type Material
17:25:06: Registering ResourceManager for type Mesh
17:25:06: Registering ResourceManager for type Skeleton
17:25:06: MovableObjectFactory for type 'ParticleSystem' registered.
17:25:06: OverlayElementFactory for type Panel registered.
17:25:06: OverlayElementFactory for type BorderPanel registered.
17:25:06: OverlayElementFactory for type TextArea registered.
17:25:06: Registering ResourceManager for type Font
17:25:06: ArchiveFactory for archive type FileSystem registered.
17:25:06: ArchiveFactory for archive type Zip registered.
17:25:06: DDS codec registering
17:25:06: FreeImage version: 3.10.0
17:25:06: This program uses FreeImage, a free, open source image library supporting all common bitmap formats. See http://freeimage.sourceforge.net for details
17:25:06: Supported formats: bmp,ico,jpg,jif,jpeg,jpe,koa,iff,lbm,pbm,pbm,pcd,pcx,pgm,pgm,png,ppm,ppm,ras,tga,targa,tif,tiff,wap,wbmp,wbm,psd,cut,xbm,xpm,dds,gif,g3,sgi,j2k,j2c,jp2
17:25:06: PVRTC codec registering
17:25:06: Registering ResourceManager for type HighLevelGpuProgram
17:25:06: Registering ResourceManager for type Compositor
17:25:06: MovableObjectFactory for type 'Entity' registered.
17:25:06: MovableObjectFactory for type 'Light' registered.
17:25:06: MovableObjectFactory for type 'BillboardSet' registered.
17:25:06: MovableObjectFactory for type 'ManualObject' registered.
17:25:06: MovableObjectFactory for type 'BillboardChain' registered.
17:25:06: MovableObjectFactory for type 'RibbonTrail' registered.
17:25:06: OGRE EXCEPTION(6:FileNotFoundException): 'plugins.cfg' file not found! in ConfigFile::load at OgreConfigFile.cpp (line 83)
17:25:06: plugins.cfg not found, automatic plugin loading disabled.
17:25:06: *-*-* OGRE Initialising
17:25:06: *-*-* Version 1.7.0 (Cthugha)
17:25:06: D3D9 : Direct3D9 Rendering Subsystem created.
17:25:06: D3D9: Driver Detection Starts
17:25:06: D3D9: Driver Detection Ends
17:25:06: OpenGL Rendering Subsystem created.
17:25:06: Particle Emitter Type 'Point' registered
17:25:06: Particle Emitter Type 'Box' registered
17:25:06: Particle Emitter Type 'Ellipsoid' registered
17:25:06: Particle Emitter Type 'Cylinder' registered
17:25:06: Particle Emitter Type 'Ring' registered
17:25:06: Particle Emitter Type 'HollowEllipsoid' registered
17:25:06: Particle Affector Type 'LinearForce' registered
17:25:06: Particle Affector Type 'ColourFader' registered
17:25:06: Particle Affector Type 'ColourFader2' registered
17:25:06: Particle Affector Type 'ColourImage' registered
17:25:06: Particle Affector Type 'ColourInterpolator' registered
17:25:06: Particle Affector Type 'Scaler' registered
17:25:06: Particle Affector Type 'Rotator' registered
17:25:06: Particle Affector Type 'DirectionRandomiser' registered
17:25:06: Particle Affector Type 'DeflectorPlane' registered
17:25:06: PCZone Factory Type 'ZoneType_Default' registered
17:25:06: CPU Identifier & Features
17:25:06: -------------------------
17:25:06: * CPU ID: GenuineIntel: Intel(R) Core(TM)2 Duo CPU E8400 @ 3.00GHz
17:25:06: * SSE: yes
17:25:06: * SSE2: yes
17:25:06: * SSE3: yes
17:25:06: * MMX: yes
17:25:06: * MMXEXT: yes
17:25:06: * 3DNOW: no
17:25:06: * 3DNOWEXT: no
17:25:06: * CMOV: yes
17:25:06: * TSC: yes
17:25:06: * FPU: yes
17:25:06: * PRO: yes
17:25:06: * HT: no
17:25:06: -------------------------
17:25:06: D3D9 : Subsystem Initialising
17:25:06: Registering ResourceManager for type Texture
17:25:06: Registering ResourceManager for type GpuProgram
17:25:06: ***************************************
17:25:06: *** D3D9 : Subsystem Initialised OK ***
17:25:06: ***************************************
17:25:06: SceneManagerFactory for type 'OctreeSceneManager' registered.
17:25:06: SceneManagerFactory for type 'TerrainSceneManager' registered.
17:25:06: SceneManagerFactory for type 'BspSceneManager' registered.
17:25:06: Registering ResourceManager for type BspLevel
17:25:06: D3D9RenderSystem::_createRenderWindow "PureBasic Ogre", 800x600 windowed miscParams: FSAA=0 displayFrequency=0 externalWindowHandle=2296814 vsync=true
17:25:06: D3D9 : Created D3D9 Rendering Window 'PureBasic Ogre' : 800x600, 32bpp
17:25:06: D3D9: Vertex texture format supported - PF_L8
17:25:06: D3D9: Vertex texture format supported - PF_L16
17:25:06: D3D9: Vertex texture format supported - PF_A8
17:25:06: D3D9: Vertex texture format supported - PF_A4L4
17:25:06: D3D9: Vertex texture format supported - PF_BYTE_LA
17:25:06: D3D9: Vertex texture format supported - PF_R5G6B5
17:25:06: D3D9: Vertex texture format supported - PF_B5G6R5
17:25:06: D3D9: Vertex texture format supported - PF_A4R4G4B4
17:25:06: D3D9: Vertex texture format supported - PF_A1R5G5B5
17:25:06: D3D9: Vertex texture format supported - PF_A8R8G8B8
17:25:06: D3D9: Vertex texture format supported - PF_B8G8R8A8
17:25:06: D3D9: Vertex texture format supported - PF_A2R10G10B10
17:25:06: D3D9: Vertex texture format supported - PF_A2B10G10R10
17:25:06: D3D9: Vertex texture format supported - PF_DXT1
17:25:06: D3D9: Vertex texture format supported - PF_DXT2
17:25:06: D3D9: Vertex texture format supported - PF_DXT3
17:25:06: D3D9: Vertex texture format supported - PF_DXT4
17:25:06: D3D9: Vertex texture format supported - PF_DXT5
17:25:06: D3D9: Vertex texture format supported - PF_FLOAT16_RGB
17:25:06: D3D9: Vertex texture format supported - PF_FLOAT16_RGBA
17:25:06: D3D9: Vertex texture format supported - PF_FLOAT32_RGB
17:25:06: D3D9: Vertex texture format supported - PF_FLOAT32_RGBA
17:25:06: D3D9: Vertex texture format supported - PF_X8R8G8B8
17:25:06: D3D9: Vertex texture format supported - PF_X8B8G8R8
17:25:06: D3D9: Vertex texture format supported - PF_R8G8B8A8
17:25:06: D3D9: Vertex texture format supported - PF_DEPTH
17:25:06: D3D9: Vertex texture format supported - PF_SHORT_RGBA
17:25:06: D3D9: Vertex texture format supported - PF_FLOAT16_R
17:25:06: D3D9: Vertex texture format supported - PF_FLOAT32_R
17:25:06: D3D9: Vertex texture format supported - PF_SHORT_GR
17:25:06: D3D9: Vertex texture format supported - PF_FLOAT16_GR
17:25:06: D3D9: Vertex texture format supported - PF_FLOAT32_GR
17:25:06: D3D9: Vertex texture format supported - PF_SHORT_RGB
17:25:06: D3D9: Vertex texture format supported - PF_PVRTC_RGB2
17:25:06: D3D9: Vertex texture format supported - PF_PVRTC_RGBA2
17:25:06: D3D9: Vertex texture format supported - PF_PVRTC_RGB4
17:25:06: D3D9: Vertex texture format supported - PF_PVRTC_RGBA4
17:25:06: RenderSystem capabilities
17:25:06: -------------------------
17:25:06: RenderSystem Name: Direct3D9 Rendering Subsystem
17:25:06: GPU Vendor: ati
17:25:06: Device Name: Monitor-1-ATI Radeon HD 4600 Series
17:25:06: Driver Version: 6.14.10.7119
17:25:06: * Fixed function pipeline: yes
17:25:06: * Hardware generation of mipmaps: yes
17:25:06: * Texture blending: yes
17:25:06: * Anisotropic texture filtering: yes
17:25:06: * Dot product texture operation: yes
17:25:06: * Cube mapping: yes
17:25:06: * Hardware stencil buffer: yes
17:25:06: - Stencil depth: 8
17:25:06: - Two sided stencil support: yes
17:25:06: - Wrap stencil values: yes
17:25:06: * Hardware vertex / index buffers: yes
17:25:06: * Vertex programs: yes
17:25:06: * Number of floating-point constants for vertex programs: 256
17:25:06: * Number of integer constants for vertex programs: 16
17:25:06: * Number of boolean constants for vertex programs: 16
17:25:06: * Fragment programs: yes
17:25:06: * Number of floating-point constants for fragment programs: 224
17:25:06: * Number of integer constants for fragment programs: 16
17:25:06: * Number of boolean constants for fragment programs: 16
17:25:06: * Geometry programs: no
17:25:06: * Number of floating-point constants for geometry programs: 0
17:25:06: * Number of integer constants for geometry programs: 0
17:25:06: * Number of boolean constants for geometry programs: 0
17:25:06: * Supported Shader Profiles: hlsl ps_1_1 ps_1_2 ps_1_3 ps_1_4 ps_2_0 ps_2_a ps_2_b ps_2_x ps_3_0 vs_1_1 vs_2_0 vs_2_a vs_2_x vs_3_0
17:25:06: * Texture Compression: yes
17:25:06: - DXT: yes
17:25:06: - VTC: no
17:25:06: - PVRTC: no
17:25:06: * Scissor Rectangle: yes
17:25:06: * Hardware Occlusion Query: yes
17:25:06: * User clip planes: yes
17:25:06: * VET_UBYTE4 vertex element type: yes
17:25:06: * Infinite far plane projection: yes
17:25:06: * Hardware render-to-texture: yes
17:25:06: * Floating point textures: yes
17:25:06: * Non-power-of-two textures: yes
17:25:06: * Volume textures: yes
17:25:06: * Multiple Render Targets: 4
17:25:06: - With different bit depths: yes
17:25:06: * Point Sprites: yes
17:25:06: * Extended point parameters: yes
17:25:06: * Max Point Size: 10
17:25:06: * Vertex texture fetch: yes
17:25:06: * Number of world matrices: 0
17:25:06: * Number of texture units: 8
17:25:06: * Stencil buffer depth: 8
17:25:06: * Number of vertex blend matrices: 0
17:25:06: - Max vertex textures: 4
17:25:06: - Vertex textures shared: no
17:25:06: * Render to Vertex Buffer : no
17:25:06: * DirectX per stage constants: yes
17:25:06: DefaultWorkQueue('Root') initialising on thread main.
17:25:06: Particle Renderer Type 'billboard' registered
17:25:06: Added resource location './.' of type 'FileSystem' to resource group 'General'
17:25:06: Texture: temp.bmp: Loading 1 faces(PF_R8G8B8,128x128x1) with hardware generated mipmaps from Image. Internal format is PF_X8R8G8B8,128x128x1.
17:25:06: Can't assign material none to SubEntity of E61612480 because this Material does not exist. Have you forgotten to define it in a .material script?

Re: [4.60 beta] Démo Physique + joints

Publié : mar. 05/avr./2011 16:37
par G-Rom
Et si tu créer un executable et qu'ensuite tu le lances via cmd , que donne le stdout ?

Re: [4.60 beta] Démo Physique + joints

Publié : mar. 05/avr./2011 21:33
par gildev
C'est incroyable! Ca donne des idées. :D

Re: [4.60 beta] Démo Physique + joints

Publié : mar. 05/avr./2011 22:03
par G-Rom
J'ai rajouté une commande , ca évite d'effacer la le mesh a chaque fois ( la ligne est une mesh ) :
; FreeEntity(3)
; CreateLine3D(3,EntityX(cube),EntityY(cube),EntityZ(cube),$FF0000,EntityX(sphere),EntityY(sphere),EntityZ(sphere),$00FF00)
UpdateLine3D(3,EntityX(cube),EntityY(cube),EntityZ(cube),$FF0000,EntityX(sphere),EntityY(sphere),EntityZ(sphere),$00FF00)

Re: [4.60 beta] Démo Physique + joints

Publié : mer. 06/avr./2011 6:57
par kelebrindae
@Gildev: Merci! Effectivement, je crois que le nouveau moteur physique de PB offre beaucoup plus de possibilités; on va bien s'amuser... :wink:

@G-Rom:
Génial, ça, c'est de la réactivité! :D
G-Rom a écrit :il manque la commande LightCastShadow(lightID, state.b)
Pour l'instant, la commande n'existe pas ("LightCastShadow is not a function, array, macro, or linked list..."). Elle sera ajoutée dans la prochaine beta comme "CreateCompositorEffect" ou "CreateRibbonEffect" ?

Re: [4.60 beta] Démo Physique + joints

Publié : mer. 06/avr./2011 7:48
par G-Rom
Normalement oui, c'est Fred qui fabrique le package, les fonction sont presente dans la dll avec le prefixe PBO_ normalement.

Re: [4.60 beta] Démo Physique + joints

Publié : mer. 06/avr./2011 8:24
par djes
J'ai retesté avec un .exe, y'a rien sur le stdout :/

Re: [4.60 beta] Démo Physique + joints

Publié : mer. 06/avr./2011 8:40
par G-Rom
avec un exe de type console?