MP3D Engine Alpha 33

Applications, Games, Tools, User libs and useful stuff coded in PureBasic
applePi
Addict
Addict
Posts: 1404
Joined: Sun Jun 25, 2006 7:28 pm

Re: MP3D Engine Alpha 32

Post by applePi »

another sequence for the gears to reduce the rotation speed for the right gear. press arrow keys to start the rotation
the problem is when we speed the motor too much it will collapse and damaged. may be there is a threshold inside the engine can be set before the motor damaged. or we can prevent the user from speeding the gears over some limit.
Image

Code: Select all

;// Project Title: MP 3D Engine Beispielprogramme
;// Dateiname: MP_GearsTest.pb
;// Erstellt am: 30.8.2013
;// Update am  :
;// Author: Michael Paulwitz
;//
;// Info:
;// Gear Test
;// Zahnrad Test
;//
;//
;////////////////////////////////////////////////////////////////
ExamineDesktops()
Global bitplanes.b=DesktopDepth(0),RX.w=DesktopWidth(0),RY.w=DesktopHeight(0),s_bg.i
MP_Graphics3D(RX,RY,0,1);MP_VSync(0)
;MP_Graphics3D (640,480,0,1)
SetWindowTitle(0, "MP3D Physik Gear Demo , press arrows carefully to start the engine") 

camera = MP_CreateCamera()    ; Kamera erstellen

MP_PositionCamera(camera, 0, 5, -5 )
MP_CameraLookAt(camera,0,0,0)

light= MP_CreateLight(0)    ; Es werde Licht

Mesh = MP_CreateRectangle (2,0.03,0.5)
ang.f=10
num = (360/ang) / 2
For i=1 To num
Mesh2 = MP_CreateRectangle (2,0.03,0.5)
angle.f+ang
MP_RotateEntity(Mesh2 , 0 , 0, angle, 1) : MP_ChangeMeshCoord(Mesh2)
MP_AddMesh(Mesh2 , Mesh ) : MP_FreeEntity(Mesh2)
Next

Mesh2 = MP_CopyEntity(Mesh)

Mesh7 = MP_CreateRectangle (0.05,4,0.05) ; axes for the middle gear
MP_RotateEntity(Mesh7 , 90 , 0, 0, 1) : MP_ChangeMeshCoord(Mesh7)
MP_AddMesh(Mesh7 , Mesh2 ) :MP_FreeEntity(Mesh7)

teapot = MP_CreateTeapot()
MP_ResizeMesh(teapot,0.5,0.5,0.5)
MP_PositionEntity (teapot,0,0,-2)
MP_RotateEntity(teapot , -90 , 0, 0, 1) : MP_ChangeMeshCoord(teapot)
MP_AddMesh(teapot , Mesh2 ) :MP_FreeEntity(teapot)

MP_FreeEntity(Mesh)
Mesh = MP_CreateRectangle (0.5,0.03,0.5)
angle = 0: ang=45
num = (360/ang) / 2
For i=1 To num
Mesh3 = MP_CreateRectangle (0.5,0.03,0.5)
angle+ang
MP_RotateEntity(Mesh3 , 0 , 0, angle, 1) : MP_ChangeMeshCoord(Mesh3)
MP_AddMesh(Mesh3 , Mesh ) : MP_FreeEntity(Mesh3)
Next

Mesh3 = MP_CopyEntity(Mesh)

MP_FreeEntity(Mesh)

MP_PositionEntity (Mesh3,-1.2,0,0) ;left gear
MP_PositionEntity (Mesh2,0,0,0)    ; middle gear

MP_RotateEntity(Mesh3, 90, 0, 0 )
MP_RotateEntity(Mesh2, 90, 0, 0 )

Mesh4 = MP_CopyEntity(Mesh3)
MP_ResizeMesh(Mesh4,0.5,0.5,0.2)

MP_PositionEntity (Mesh4,0,0,-1)  
MP_RotateEntity(Mesh4 , -90 , 0, 0, 1)
MP_ChangeMeshCoord(Mesh4)
MP_AddMesh(Mesh4 , Mesh2 ) : MP_FreeEntity(Mesh4)

Mesh5 = MP_CopyEntity(Mesh2)
MP_PositionEntity (Mesh5,1.2,1.1,0)  ; right gear

MP_EntitySetNormals (Mesh3)
MP_MaterialDiffuseColor (Mesh3,255,255,0,0)
MP_MaterialSpecularColor (Mesh3, 255, 255 ,0, 0,5)
MP_EntitySetNormals (Mesh2)
MP_MaterialDiffuseColor (Mesh2,255,255,128,50)
MP_MaterialSpecularColor (Mesh2, 255, 255 ,255, 155,5)
MP_EntitySetNormals (Mesh5)
MP_MaterialDiffuseColor (Mesh5,255,255,255,50)
MP_MaterialSpecularColor (Mesh5, 255, 255 ,255, 155,5)

; repositioning of all meshes
MP_PositionEntity (Mesh3,-1.7,-0.5,0) ; left gear
MP_PositionEntity (Mesh2,-0.5,-0.5,0) ; middle gear
MP_PositionEntity (Mesh5,0.7,0.6,0)   ; right gear

MP_PhysicInit()
MP_EntityPhysicBody(Mesh3 , 5, 10)
MP_ConstraintCreateHinge (Mesh3,0,1,0)

MP_EntityPhysicBody(Mesh2, 5, 10)
MP_ConstraintCreateHinge (Mesh2,0,10,0)

MP_EntityPhysicBody(Mesh5 , 5, 10)
MP_ConstraintCreateHinge (Mesh5,0,10,0)

MP_AmbientSetLight (RGB(0,100,200))


While Not MP_KeyDown(#PB_Key_Escape) And Not WindowEvent() = #PB_Event_CloseWindow; Esc abfrage oder Windows Schliessen
       
    If MP_KeyDown(#PB_Key_Up)
          omega.f + 0.5
        ElseIf MP_KeyDown(#PB_Key_Down)
          omega.f - 0.5
        EndIf  
        MP_EntitySetOmega(Mesh3, 0 , omega ,0)

    
    MP_PhysicUpdate()
    
    MP_RenderWorld() ; Erstelle die Welt
    MP_Flip () ; Stelle Sie dar
    
Wend
  
MP_PhysicEnd()
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Re: MP3D Engine Alpha 32

Post by Psychophanta »

@ApplePi, i think the issue of it is inside Newton internals, however the solution for that is to be able to force the axis and the position of the hinges to be static. In that way there could not be possibility to destroy the artefact :)
http://www.zeitgeistmovie.com

while (world==business) world+=mafia;
mpz
Enthusiast
Enthusiast
Posts: 497
Joined: Sat Oct 11, 2008 9:07 pm
Location: Germany, Berlin > member German forum

Re: MP3D Engine Alpha 32

Post by mpz »

Hi,

yes i have 1100 fps with the galaxy file and yes i have 880 with the other file. How many fps make the following file ? Please test it.
http://www.flasharts.de/mpz/Galaxie.exe

i have a amd dual core amd cpu and a ati hd 6870 graficcard, but my System is 2 years old. I will test both files with older systems, perhaps i find an older sytem to fix it.

@ applePi
You new motor demo is very nice. I will ask in the newton forum how to fix the problem. It must be a solution for that kind of problem....

Greetings
Michael
Working on - MP3D Library - PB 5.73 version ready for download
applePi
Addict
Addict
Posts: 1404
Joined: Sun Jun 25, 2006 7:28 pm

Re: MP3D Engine Alpha 32

Post by applePi »

Michael, i have forgotten to say that i run my computer in resolution 640 X 480
so running your Galaxy.exe result in
FPS = 248, surfaceHeigh = 1040, SurfaceWidth = 1420
but when increasing the resolution to 1024 X 768
the result degrades to:
fps = 206. so may be Psychophanta screen have too much resolution and (or) his graphics card are internal with the motherboard which are mostly have low performance.
the manual date of my computer is December 2006
asus V-Series P5V900
but i have added Geforce GT 520 to it recently, it has 2 GB DDR3 memory, i have found during years that nvidea Geforce even the old cards have a good performance.
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Re: MP3D Engine Alpha 32

Post by Psychophanta »

mpz wrote:yes i have 1100 fps with the galaxy file and yes i have 880 with the other file. How many fps make the following file ? Please test it.
http://www.flasharts.de/mpz/Galaxie.exe
FPS: 160
My test machine: ATI RADEON HD 4200 in a AMD PHENOM X2 550 dual core, 3.11GHz
All it was tested at: 1920x1200 resolution (16:10 aspect ratio), which is the resolution of my desktop (26'' monitor)
http://www.zeitgeistmovie.com

while (world==business) world+=mafia;
User avatar
Sveinung
Enthusiast
Enthusiast
Posts: 142
Joined: Tue Oct 07, 2003 11:03 am
Location: Bergen, Norway

Re: MP3D Engine Alpha 32

Post by Sveinung »

If we are testing...

FPS: 2884
Running GTX 770

Sveinung
Mythros
Enthusiast
Enthusiast
Posts: 306
Joined: Mon Aug 19, 2013 3:28 pm

Re: MP3D Engine Alpha 32

Post by Mythros »

Hi, @mpz. Found the problem to why it's still crashing in threaded mode & unicode mode sometimes.

You forgot to add a threadsafe & unicode x86 version of "MP3D_Library" to "PureBasic\SubSystems\DX9\purelibraries\userlibraries"

Without this, I can't compile my EXE at all without a POLINK error, in both unicode AND / OR thread mode. I tried both, then I tried each seperate. All 3 crashed, but I was able to isolate the above error.

PLEASE fix this.

Thank you so very kindly! :)

Myth
mpz
Enthusiast
Enthusiast
Posts: 497
Joined: Sat Oct 11, 2008 9:07 pm
Location: Germany, Berlin > member German forum

Re: MP3D Engine Alpha 32

Post by mpz »

Hi Mythros,

i have made a special version here:
http://www.morty-productions.de/gamedev ... hp?tid=160

go to the first side and download the following version:

x86 for pb 511 with unicode an threadsave
http://www.flasharts.de/mpz/mp33/PB511_ ... ibrary.zip

Okay?

Greetings Michael
Working on - MP3D Library - PB 5.73 version ready for download
Mythros
Enthusiast
Enthusiast
Posts: 306
Joined: Mon Aug 19, 2013 3:28 pm

Re: MP3D Engine Alpha 32

Post by Mythros »

Hi, mpz. Thank you, but for some reason, I'm still getting a "Polink" error when I replace the library and try to compile my script after restarting PureBasic.
User avatar
N_Gnom
User
User
Posts: 76
Joined: Fri Sep 13, 2013 3:20 pm
Location: Germany

Re: MP3D Engine Alpha 32

Post by N_Gnom »

@mpz: have you any news about full support of b3d format?
i´m asking ´cause i have some models with many textures per mesh and so i need this...
or another 3d format wich support textures per surfaces....
applePi
Addict
Addict
Posts: 1404
Joined: Sun Jun 25, 2006 7:28 pm

Re: MP3D Engine Alpha 32

Post by applePi »

the idea of pendulum clock depends on restricting the rotation of the gear, else the spring or the weight will loose its energy immediately.
several ideas in the construction such as the idea of escapement :The basic idea that is being demonstrated , for each swing of the pendulum back and forth, one tooth of the gear is allowed to "escape." look the flash demo at the middle of this page:
http://electronics.howstuffworks.com/ga ... /printable
Image
press space for more testing of the escape mechanism. i have made too much testing until i found this configuration even not optimal but works. still it needs Tick Tack sound like that in the flash video in the above link.
the source of power which rotates the gear either a spring or a weight. and here it is the MP_EntityAddImpulse(Mesh, ...) which are more suitable in this case than a motor which have irresistible force.
the following program is an approximate implementation of the flash video in the above article. and thanks for Michael for implementing the gears and adding type 5 to the physics .
to run the code install mp3d from here:
http://www.purebasic.fr/english/viewtop ... 27&t=43601
then download the yet experimental MP3D_Library from here http://www.morty-productions.de/gamedev ... hp?tid=160 and copy it over the file in C:\PureBasic\SubSystems\DX9\purelibraries\userlibraries
i have buyed a pendulum clock toy called "first time clock" especially for this example to see exactly how the pendulum / escapement works and still does not fit fully in my imagination, so we appreciate too much the original inventors of this device.
Image

Code: Select all

ExamineDesktops()
Global bitplanes.b=DesktopDepth(0),RX.w=DesktopWidth(0),RY.w=DesktopHeight(0),s_bg.i
MP_Graphics3D(RX,RY,0,1);MP_VSync(0)
SetWindowTitle(0, "MP3D Physik Pendulum & Escapement demo, press Space , Z for more testing ") 

camera = MP_CreateCamera()    ; Kamera erstellen

MP_PositionEntity(camera, 0, 0, -5 )
MP_EntityLookAt(camera,0,0,0)

light= MP_CreateLight(0)    ; Es werde Licht

MP_AmbientSetLight (RGB(0,100,200))

;construction of a gear with 18 teeth
ang=40 ; the angle wanted for every tooth of the gear
Mesh = MP_CreateCylinder(10,0.2)
For i=1 To 18
angle.f+20
x.f = Cos(Radian(angle)) * 1: z.f = Sin(Radian(angle)) * 1
Mesh2 = MP_CreateRectangle (0.5,0.05,0.2)
MP_PositionEntity (Mesh2,x,z,0)
ang+20
MP_RotateEntity(Mesh2 , 0 , 0, ang)
MP_ChangeMeshCoord(Mesh2)
MP_AddMesh(Mesh2 , Mesh ) : MP_FreeEntity(Mesh2)
Next

MP_EntitySetNormals (Mesh)
MP_MaterialDiffuseColor (Mesh,255,255,255,50)
MP_MaterialSpecularColor (Mesh, 255, 255 ,255, 155,5)
;MP_MeshSetAlpha(Mesh, 1)

escape = MP_CreateRectangle (1.5,0.05,0.2) ;the rod above the gear teeth
MP_PositionEntity (escape, 0, 0, 0)
escape2 = MP_CreateRectangle (0.5,0.05,0.2) ; the right small piece attached to the rod
MP_PositionEntity (escape2, 0.7, -0.1, 0)
MP_RotateEntity(escape2 , 0 , 0, 90)
MP_ChangeMeshCoord(escape2)
MP_AddMesh(escape2 , escape ) : MP_FreeEntity(escape2)

escape2 = MP_CreateRectangle (0.5,0.05,0.2) ; the left small piece attached to the rod
MP_PositionEntity (escape2, -0.7, -0.1, 0)
MP_RotateEntity(escape2 , 0 , 0, -100)
MP_ChangeMeshCoord(escape2)
MP_AddMesh(escape2 , escape ) : MP_FreeEntity(escape2)

; pendulum
Mesh7 = MP_CreateRectangle (0.05,2.5,0.05)
MP_PositionEntity (Mesh7, 0, -1.3, -0.3)
MP_ChangeMeshCoord(Mesh7)
MP_AddMesh(Mesh7 , escape ) :MP_FreeEntity(Mesh7)

sphere = MP_CreateSphere(10)
MP_ResizeMesh(sphere,0.5,0.5,0.3)
MP_PositionEntity (sphere, 0, -2.3,  -0.5)
;MP_ChangeMeshCoord(sphere)
;MP_AddMesh(sphere , escape ) :MP_FreeEntity(sphere)

; repositioning of the rod and its 2 attached pieces above the gear teeth
MP_PositionEntity (escape, 0, 1.35, 0) ; repositioning of the rod and its 2 attached pieces above the gear teeth

MP_EntitySetNormals (escape)
MP_MaterialDiffuseColor (escape,255,33,255,50)
MP_MaterialSpecularColor (escape, 255, 255 ,255, 155,5)

MP_PhysicInit()
MP_ChangeMeshCoord(sphere)
;MP_EntityPhysicBody(sphere , 5, 1)
MP_AddMesh(sphere , escape ) :MP_FreeEntity(sphere)

MP_EntityPhysicBody(escape , 5, 2)
;MP_ConstraintCreateHinge(Entity, PinX.f, PinY.f, PinZ.f [, Pivotx.f, Pivoty.f, Pivotz.f [, MasterEntity]]); create a Hinge joint functions 
MP_ConstraintCreateHinge (escape,0,0,1)

MP_EntityPhysicBody(Mesh , 5, 10)
MP_ConstraintCreateHinge (Mesh,0,0,1)
;MP_EntitySetWind(Mesh, 1.0 , 1.0 ,0)


While Not MP_KeyDown(#PB_Key_Escape) And Not WindowEvent() = #PB_Event_CloseWindow; Esc abfrage oder Windows Schliessen
        
    MP_EntityAddImpulse(Mesh, 0, -0.5, 0 , -1.7,0, 0)
    
   If MP_KeyHit(#PB_Key_Space)
          MP_EntityAddImpulse(escape, -1, 0, 0 , 1,0, 0)
          MP_EntityAddImpulse(Mesh, 0, -0.1, 0 , -1.7,0, 0)
        ElseIf MP_KeyHit(#PB_Key_Z) 
          MP_PositionEntity (escape, 0, 2.5, 0)
          
   EndIf
    
    MP_PhysicUpdate()
    
    MP_RenderWorld() ; Erstelle die Welt
    MP_Flip () ; Stelle Sie dar
    
Wend
  
MP_PhysicEnd()
code Edited: July 19 2014 to be compatible with current library
Last edited by applePi on Sat Jul 19, 2014 9:35 am, edited 1 time in total.
mpz
Enthusiast
Enthusiast
Posts: 497
Joined: Sat Oct 11, 2008 9:07 pm
Location: Germany, Berlin > member German forum

Re: MP3D Engine Alpha 32

Post by mpz »

Hi,

@Mythros what exactly for a pb version do you use? Have you activated the unicode and threadsave compiler funtion? What say exactly the error message?

@N_Gnom i am working on a better import of the b3d format, but i needs some more time...

@applePi your physic pendulum is very greate. There is a function in newton possible to make a sound if two body hit each other. I will implement these function, then you can make and hear the click...


Greetings Michael
Working on - MP3D Library - PB 5.73 version ready for download
Mythros
Enthusiast
Enthusiast
Posts: 306
Joined: Mon Aug 19, 2013 3:28 pm

Re: MP3D Engine Alpha 32

Post by Mythros »

@mpz, the error i get is when I use either unicode OR threadsafe with dx9 subsystem. It also happens when i use both unicode AND threadsafe.

The error I get is:
POLINK: error: Unresolved external symbol '_SYS_CheckStringBuffer'.
POLINK: fatal error: 1 unresolved external(s).
Thanks, mpz
mpz
Enthusiast
Enthusiast
Posts: 497
Joined: Sat Oct 11, 2008 9:07 pm
Location: Germany, Berlin > member German forum

Re: MP3D Engine Alpha 32

Post by mpz »

Hi Mythros,

the version i had made was for PB 5.11 = x86 for pb 511 with unicode an threadsave.
Do you use these version or not?

P. S I think the error message comes if you use PB 5.20

Greetings Michael
Working on - MP3D Library - PB 5.73 version ready for download
User avatar
Sveinung
Enthusiast
Enthusiast
Posts: 142
Joined: Tue Oct 07, 2003 11:03 am
Location: Bergen, Norway

Re: MP3D Engine Alpha 32

Post by Sveinung »

@MPZ

Have you started on the 5.20 Version? Just wondered! (and I miss your lib :D )

Regards
Sveinung
Post Reply