MP3D Engine Alpha 33

Applications, Games, Tools, User libs and useful stuff coded in PureBasic
mpz
Enthusiast
Enthusiast
Posts: 497
Joined: Sat Oct 11, 2008 9:07 pm
Location: Germany, Berlin > member German forum

Re: MP3D Engine Alpha 31

Post by mpz »

Hi applePi,

In my first installer i wrote the *.lib files (d3d9.lib) in the wrong folder, the correct folder are C:\PureBasic\PureLibraries\Windows\Libraries. The new installer working correct now...

Thanks for you work, i will get your demos to the mp3d_demos in the next version...

Her comes a peace of code to add different meshs to a new one with different colors. Her you can see the new comand MP_ChangeMeshCoord(Mesh) to turn vertex with a mesh matrix:

The first new function for the next version is MP_MouseButtonHit (Button). Now you get only one trigger if you push the mousebutton ...

Greetings Michael

Code: Select all

;////////////////////////////////////////////////////////////////
;//
;// Project Title: MP 3D Engine Beispielprogramme
;// Dateiname: MP_Mesh_Create_a_new_mesh.pb
;// Erstellt am: 30.3.2011
;// Update am  : 
;// Author: Michael Paulwitz
;// 
;// Info: 
;// Mesh Create Demo
;// Demo from @graphy
;//
;////////////////////////////////////////////////////////////////

Structure D3DXVector3
    x.f
    y.f
    z.f
EndStructure

MP_Graphics3D(800, 600, 32, 1)

MP_CreateLight(1)

cam0 = MP_CreateCamera()
MP_CameraSetRange(cam0, 4, 2048)
MP_PositionCamera(cam0, -16, -16, -22)
MP_CameraLookAt(cam0, 0, 0, 0)

;Create a empty mesh
cordx = MP_CreateMesh()

;Create the cylinder of the mesh
cyl0 = MP_CreateCylinder(10, 20)
MP_ScaleMesh(cyl0, 0.5, 0.5, 1)
MP_AddMesh(cyl0, cordx)
MP_FreeEntity(cyl0)

;Create the first cone of the mesh
con0 = MP_CreateCone(10, 4)
MP_PositionMesh(con0, 0, 0, -12)
MP_AddMesh(con0, cordx)
MP_FreeEntity(con0)

;Create the second cone of the mesh
con1 = MP_CreateCone(10, 4)
MP_RotateEntity(con1, 180, 0, 0)
MP_ChangeMeshCoord(con1)
MP_PositionMesh(con1, 0, 0, 12)
MP_AddMesh(con1, cordx)
MP_EntitySetColor(cordx, MP_ARGB(255, 0, 0, 255))
MP_FreeEntity(con1)

;Create the x+ of the mesh
xplus = MP_Create3DText("", "x+", 4)
MP_EntitySetColor(xplus, MP_ARGB(255, 255, 0, 0))
MP_PositionMesh(xplus, 5, 1, 0)

; This add the xplus mesh to the cordx mesh
MP_RotateEntity(xplus, -90, 0, 0)
MP_ChangeMeshCoord(xplus)
MP_AddMesh(xplus, cordx)
MP_FreeEntity(xplus)

;Create the x- of the mesh
xminus = MP_Create3DText("", "x-", 4)
MP_EntitySetColor(xminus, MP_ARGB(255, 0, 255, 0))
MP_PositionMesh(xminus, -9, 1, 0)

; This add the xminus mesh to the cordx mesh
MP_RotateEntity(xminus, -90, 0, 0)
MP_ChangeMeshCoord(xminus)
MP_AddMesh(xminus, cordx)
MP_FreeEntity(xminus)

MP_SaveMesh("cordx.x",cordx) ; you see a mesh with different meshs

While Not MP_KeyDown(#PB_Key_Escape) And Not WindowEvent() = #PB_Event_CloseWindow
  
  MP_TurnEntity (cordx,0.1,0.1,0.1) 
  
  MP_RenderWorld()
  MP_Flip()
  
Wend
Working on - MP3D Library - PB 5.73 version ready for download
applePi
Addict
Addict
Posts: 1404
Joined: Sun Jun 25, 2006 7:28 pm

MP_SpriteSetZ and billboards

Post by applePi »

Hi
how to use MP_SpriteSetZ so sprite will be like a billboard, in the following i want to display the sun from the picture "C:\PureBasic\Examples\3D\Data\Textures\Lensflare5.jpg"
now if i use MP_SpriteSetZ(Sprite , 10) or MP_SpriteSetZ(Sprite , 1000)
it gives the same size of the sprite, while i think it should be smaller due to distance. also MP_SpriteSetZ(Sprite , 1001) makes the sprite to diappear.
in fact i want to display a sun rotating through the z like in the PB example StaticGeometry.pb
thanks

Code: Select all

MP_Graphics3D (640,480,0,1) ; Erstelle ein WindowsFenster #Window = 0
 
SetWindowTitle(0, "Demo von DeepText und DeepSprite") 
Sprite = MP_CatchSprite(?pic, ?picend-?pic) 

MP_TransparentSpriteColor(Sprite, $FFFFFF) 

camera=MP_CreateCamera() ; Kamera erstellen

light=MP_CreateLight(1) ; Es werde Licht

MP_VSync(1)

While Not MP_KeyDown(#PB_Key_Escape) And Not WindowEvent() = #PB_Event_CloseWindow; Esc abfrage oder Windows Schliessen
   
    MP_SpriteSetZ(Sprite , 10)
    MP_TurnSprite(Sprite, 2)
    MP_DrawSprite(Sprite, 200, 150,255)
    
                  
     MP_RenderWorld() ; Erstelle die Welt

     MP_Flip () ; Stelle Sie dar

Wend

DataSection
   pic: IncludeBinary "Lensflare5.jpg";
   picend:
EndDataSection
mpz
Enthusiast
Enthusiast
Posts: 497
Joined: Sat Oct 11, 2008 9:07 pm
Location: Germany, Berlin > member German forum

Re: MP3D Engine Alpha 31

Post by mpz »

hi applePi,

the size of a sprite are all times the same size, but you can put a sprite in front or back of a mesh. The only posibility is to use the MP_ScaleSprite to change the size. Here i send yo a little example of these function...

Perhaps i will make offical billboard function int mp3d in the future...

Greetings Michael

Code: Select all

MP_Graphics3D (640,480,0,1) ; Erstelle ein WindowsFenster #Window = 0
 
SetWindowTitle(0, "Demo von DeepText und DeepSprite") 
Sprite = MP_CatchSprite(?pic, ?picend-?pic) 

MP_TransparentSpriteColor(Sprite, $FFFFFF) 

camera=MP_CreateCamera() ; Kamera erstellen

light=MP_CreateLight(1) ; Es werde Licht

MP_VSync(1)

sphere = MP_CreateSphere(6)

MP_PositionMesh(sphere,0,0,10)



While Not MP_KeyDown(#PB_Key_Escape) And Not WindowEvent() = #PB_Event_CloseWindow; Esc abfrage oder Windows Schliessen
  
   n.f+0.01
  
    MP_SpriteSetZ(Sprite , 10+Sin(n)*2)
    
    MP_ScaleSprite(Sprite, 100 - Sin(n)*20,100 - Sin(n)*20)

    MP_TurnSprite(Sprite, 2)
    MP_DrawSprite(Sprite, 280, 150,255)
    
                  
     MP_RenderWorld() ; Erstelle die Welt

     MP_Flip () ; Stelle Sie dar

Wend

DataSection
   pic: IncludeBinary "Lensflare5.jpg";
   picend:
EndDataSection
Working on - MP3D Library - PB 5.73 version ready for download
User avatar
AndyLy
Enthusiast
Enthusiast
Posts: 228
Joined: Tue Jan 04, 2011 11:50 am
Location: GRI

Re: MP3D Engine Alpha 31

Post by AndyLy »

I can not light an object with texture. Without texture, everything is fine.
Tried all the commands (commented)- have no effect. What am I doing wrong?

Code: Select all

MP_Graphics3D (640,480,0,1) 
camera=MP_CreateCamera() 
light=MP_CreateLight(2)
MP_LightSetColor (light, RGB(255,0,0))
MP_PositionEntity (light,-2,2,0)
Mesh  = MP_CreateSphere(16)
MP_PositionEntity (Mesh,0,0,5)
mytex1=MP_LoadTexture("01161.jpg")
MP_EntitySetTexture (Mesh, mytex1)
;MP_MaterialAmbientColor (Mesh,255,255,255,255) 
;MP_MaterialDiffuseColor (Mesh,255,255,255,255)
;MP_EntitySetColor(mesh,RGB(255,0,0))

While Not MP_KeyDown(#PB_Key_Escape)
      MP_RenderWorld () 
      MP_Flip () 
Wend 
'Happiness for everybody, free, and no one will go away unsatisfied!'
SMsF town: http://www.youtube.com/watch?v=g6RRKYf_Pd0
SMf locations module (Ogre). Game video: http://www.youtube.com/watch?v=ZlhBgPJhAxI
applePi
Addict
Addict
Posts: 1404
Joined: Sun Jun 25, 2006 7:28 pm

Re: MP3D Engine Alpha 31

Post by applePi »

i see the texture lighted, but to color it i have tried this
MP_MaterialEmissiveColor (mytex1, 0, 255, 255, 0)
to make the texture emit yellow color
MP_MaterialEmissiveColor (mytex1, 0, 255, 255, 255)
for white color ... etc
there is also
MP_MaterialSpecularColor(...)
another note:
While Not MP_KeyDown(#PB_Key_Escape) And Not WindowEvent() = #PB_Event_CloseWindow
will display the mouse cursor as normal pointer instead of the busy hour glass cursor.

regards
User avatar
AndyLy
Enthusiast
Enthusiast
Posts: 228
Joined: Tue Jan 04, 2011 11:50 am
Location: GRI

Re: MP3D Engine Alpha 31

Post by AndyLy »

Let me explain.
Without texture I get this.
Image
With texture I get this.
Image
I need this.( Object illuminated by red light and textured.)
Image
'Happiness for everybody, free, and no one will go away unsatisfied!'
SMsF town: http://www.youtube.com/watch?v=g6RRKYf_Pd0
SMf locations module (Ogre). Game video: http://www.youtube.com/watch?v=ZlhBgPJhAxI
applePi
Addict
Addict
Posts: 1404
Joined: Sun Jun 25, 2006 7:28 pm

Re: MP3D Engine Alpha 31

Post by applePi »

try this code with this image (256x256):
Image
using:
MP_MaterialSpecularColor(mytex1,0,255,0,0,1)
MP_MaterialEmissiveColor (mytex1,0,255,0,0)

i got this picture with a red reflection on the left side:
Image
but using only
MP_MaterialSpecularColor(mytex1,0,255,0,0,1)
i got this picture with red spot:
Image
change the x position of the light from -12 to 12 and the reflection will be on the right. use the suitable mixture of colors you want for MP_MaterialEmissiveColor and MP_MaterialSpecularColor and MP_LightSetColor

Code: Select all

MP_Graphics3D (640,480,0,1) 
camera=MP_CreateCamera() 
light=MP_CreateLight(2)
MP_LightSetColor (light, RGB(255,0,0))
MP_PositionEntity (light,-12,2,-5)
Mesh  = MP_CreateSphere(16)
MP_PositionEntity (Mesh,0,0,5)
mytex1=MP_LoadTexture("earth.png")
MP_EntitySetTexture (Mesh, mytex1)

MP_MaterialSpecularColor(mytex1,0,255,0,0,1)
MP_MaterialEmissiveColor (mytex1,0,255,0,0)
While Not MP_KeyDown(#PB_Key_Escape) And Not WindowEvent() = #PB_Event_CloseWindow; Esc abfrage oder schliessen  
      MP_RenderWorld () 
      MP_Flip () 
Wend
User avatar
AndyLy
Enthusiast
Enthusiast
Posts: 228
Joined: Tue Jan 04, 2011 11:50 am
Location: GRI

Re: MP3D Engine Alpha 31

Post by AndyLy »

Thank you for your reply. While this is not exactly what I wanted, but thanks to you, I found a bug in my code.
Try your code- illumination of the planet does not depend on the color of the light.
And the shadow of sphere disappears when textured.
And I want to make, for example, red sun, which will illuminate all of the objects in red.

By the way, there is a way to smooth the mesh boundary?

Update :
Okay, I will do almost what I wanted, though not realized until the end of how it works.

Image

But when used bump mapping all the shadows disappeared.

Image

P.s.
With lighting like understood. How to make a background? I want to draw a stars.
'Happiness for everybody, free, and no one will go away unsatisfied!'
SMsF town: http://www.youtube.com/watch?v=g6RRKYf_Pd0
SMf locations module (Ogre). Game video: http://www.youtube.com/watch?v=ZlhBgPJhAxI
applePi
Addict
Addict
Posts: 1404
Joined: Sun Jun 25, 2006 7:28 pm

Re: MP3D Engine Alpha 31

Post by applePi »

illumination of the planet does not depend on the color of the light
it has some effect ,change the light to blue
MP_LightSetColor (light, RGB(0,0,255))
and you will see the picture different from the complete red
http://s7.postimage.org/ir1gwz2nv/earth_red_blue.png
also if changing the color to green , and also that affected by the colors used in the other funcions.
in ideal world the body who reflect only green color and we light it with red color it will appear black, but the color in practice are not complete pure. in fact i have some ambiguity about the color,textures, materials subject . this example MP3D Demos\Material\MP_MaterialTest.pb may be usefull .
"is a way to smooth the mesh boundary?"
i don't know , but there may be a way http://www.gamedev.net/topic/515978-gl_ ... direct3d-/
since MP3D are using directX 9.
in openGl there is "GL_POLYGON_SMOOTH" look the question here about the same subject but in opengl, the demo are beautifull
http://www.thinbasic.com/community/show ... jects-quot

regarding the bump mapping try the example:
C:\PureBasic\MP3D Demos\Effects\MP_Bumpmap.pb
i have added the light color weak yellow (RGB(100,100,0), and the light position, and the MP_MaterialSpecularColor and MP_MaterialEmissiveColor, so the rotating earth with Bumpmap appears like the picture below, and there is shadow near the edges, unless you mean you want darker color on the far side of the earth from the sun. i don't know about this yet. and it is a good exercise. the problem is i guess that the textures have self light so we have to make it darker.
save the modified code to the C:\PureBasic\MP3D Demos\Effects\ folder
Image

Code: Select all

;// example MP_Bumpmap.pb modified slightly
MP_Graphics3D (640,480,0,3) ; Create Windows #Window = 0
SetWindowTitle(0, "3D Bumpmap Demo, left world / right with created normals") ; Name

camera=MP_CreateCamera() ; Create Camera

x.f=0 : y.f=0 : z.f = -4 
MP_PositionCamera(camera,x.f,y.f,z.f) ; Camera position 
light=MP_CreateLight(2) ; Light on 
MP_LightSetColor (light, RGB(100,100,0))
MP_PositionEntity (light,-12,2,-5)
MP_PositionEntity (light,-5,2,-2)
earth1=MP_CreateSphere(20) ; Sphere 1
;earth2=MP_CreateSphere(20) ; Sphere 2

Textur=MP_CatchTexture(?Earth_map,?Earth_map_end-?Earth_map)
;MP_CatchTexture(Adresse, Laenge [, Alpha [, MipLevels]])
;MP_CreateNormalMap(Texture, Type, Factor.f)
Textur2 = MP_CreateNormalMap(Textur, 4, 25) ; Erzeugt eine Normal Map aus der Textur  

MP_EntitySetTexture (earth1,textur)
MP_EntitySetBumpmap (earth1,textur2)

;MP_EntitySetTexture (earth2,textur)

;MP_PositionEntity (Earth2,-1,0,0) ; Position Earth2 
MP_MaterialSpecularColor(textur,1,100,100,0,1)
MP_MaterialEmissiveColor (textur,1,100,100,0)

While Not MP_KeyDown(#PB_Key_Escape) And Not WindowEvent() = #PB_Event_CloseWindow; Esc or close

    MP_TurnEntity (earth1,-0.05,0,0) ; Move Earth1
    ;MP_TurnEntity (earth2,-0.05,0,0) ; Move Earth2
    MP_RenderWorld () ; Hier gehts los
    MP_Flip () ; 

Wend

DataSection
  Earth_map:
  IncludeBinary  "earth_map.jpg" ; Mein MP Bild included
  Earth_map_end:
EndDataSection
User avatar
AndyLy
Enthusiast
Enthusiast
Posts: 228
Joined: Tue Jan 04, 2011 11:50 am
Location: GRI

Re: MP3D Engine Alpha 31

Post by AndyLy »

applePi Thank you for your help.
Almost got what I wanted. I'm so cool. :D

https://rapidshare.com/files/3670389323/Solarsys.exe
'Happiness for everybody, free, and no one will go away unsatisfied!'
SMsF town: http://www.youtube.com/watch?v=g6RRKYf_Pd0
SMf locations module (Ogre). Game video: http://www.youtube.com/watch?v=ZlhBgPJhAxI
applePi
Addict
Addict
Posts: 1404
Joined: Sun Jun 25, 2006 7:28 pm

Re: MP3D Engine Alpha 31

Post by applePi »

I really like it, the planets marching around the sun in a grand tour, and the background of the stars and galaxies. the most important is that it does not eat the memory, since it is stable in the Task manager at about 16 MB, while opera browser eat 133MB at the same time.
if you want you can add music, yesterday i have seen the example MP_Soundeffekt.pb in MP3D Demos\Sound\ folder but i haven't studied it yet.
regards
User avatar
AndyLy
Enthusiast
Enthusiast
Posts: 228
Joined: Tue Jan 04, 2011 11:50 am
Location: GRI

Re: MP3D Engine Alpha 31

Post by AndyLy »

I'm not going to make this something finished. I just wanted to try the "creation" of mpz. May be I'm using his library, in my new game.
'Happiness for everybody, free, and no one will go away unsatisfied!'
SMsF town: http://www.youtube.com/watch?v=g6RRKYf_Pd0
SMf locations module (Ogre). Game video: http://www.youtube.com/watch?v=ZlhBgPJhAxI
User avatar
Sveinung
Enthusiast
Enthusiast
Posts: 142
Joined: Tue Oct 07, 2003 11:03 am
Location: Bergen, Norway

Re: MP3D Engine Alpha 31

Post by Sveinung »

Some old demofx...

Code: Select all

If MessageRequester("SinDeform","Full Screen?",#MB_ICONQUESTION|#PB_MessageRequester_YesNo)=#PB_MessageRequester_Yes
  ExamineDesktops()
  mp_graphics3d(DesktopWidth(0),DesktopHeight(0),0,0)
Else
  mp_graphics3d(800,600,0,3)
EndIf

SetWindowTitle(0,"Sine Deform")

cam=mp_createcamera()
mp_positioncamera(cam,0,0,-4)
lig=mp_createlight(1)

sp=mp_createsphere(40)
MP_MaterialDiffuseColor (sp,255,0,255,0)
MP_MaterialAmbientColor (sp, 255, 128 , 255, 128) ; 
MP_MaterialSpecularColor (sp, 255, 128 ,255, 128,40) ; 

sp_o=MP_CopyEntity(sp)
MP_HideEntity(sp_o,1)

MP_VSync(1)
MP_Wireframe(0)

Repeat
  
  dtime.f=ElapsedMilliseconds()/300
  fx.f=(5+Sin(dtime)*4)/2
  fy.f=(5+Sin(dtime*1.3)*4)/2
  fz.f=(5+Sin(dtime*1.1)*4)/2
  a.f=(35+Sin(dtime*1.4)*3)/50
  
  For i=0 To mp_countvertices(sp)-1
    nx.f=MP_VertexGetNX(sp_o,i)
    ny.f=MP_VertexGetNY(sp_o,i)
    nz.f=MP_VertexGetNZ(sp_o,i)
    f.f=Sin((nx*fx)+dtime)*Sin((ny*fy)+dtime)*Sin((nz*fz)+dtime)
    vx.f=MP_VertexGetX(sp_o,i)+nx*f*a
    vy.f=MP_VertexGetY(sp_o,i)+ny*f*a
    vz.f=MP_VertexGetZ(sp_o,i)+nz*f*a
    MP_VertexSetX(sp,i,vx)
    MP_VertexSetY(sp,i,vy)
    MP_VertexSetZ(sp,i,vz)
  Next
  MP_EntitySetNormals(sp)
  mp_renderworld()
  
  mp_flip()
Until mp_keydown(#PB_Key_Escape) Or WindowEvent()=#PB_Event_CloseWindow
End

Regards
Sveinung
applePi
Addict
Addict
Posts: 1404
Joined: Sun Jun 25, 2006 7:28 pm

Re: MP3D Engine Alpha 31

Post by applePi »

Sveinung, that is really a great demo, thank you very much

Update:
i have catched a good instance of the deformation and saved it to x model
by inserting MP_SaveMesh("model.x",sp) before the last line "End" here is the model.
http://www.mediafire.com/?n5lc7entifo0yd5

i like this feature introduced recently very much
User avatar
AndyLy
Enthusiast
Enthusiast
Posts: 228
Joined: Tue Jan 04, 2011 11:50 am
Location: GRI

Re: MP3D Engine Alpha 31

Post by AndyLy »

I have a new problem: I want to draw a Plane with transparent texture. But transparency is obtained only for the back surface, and objects do not. See the picture.
And how to change the transparency of the textures?
MP_TextureSetColor() changes the transparency of entire texture, but draws a "transparent" color.

Decided to refuse mesh and just use a sprite but could not find command transformation. There is no command like TransformSprite3D (), in MP3D?

Image

P.s. I have a strange bug, after adding the new Mesh (Plane) one of the planets incorrectly identifies the location of the light source. It is not clear why only one. Meshes do not overlap does not interfere with each other.

Clarification: it occurs exactly once when I do MP_MeshSetAlpha (Plane1, 1), then the planet MP_MeshSetAlpha (Plan1, 3). If you put MP_MeshSetAlpha (Plane1, 3), then everything is fine, but I need mode 1.
'Happiness for everybody, free, and no one will go away unsatisfied!'
SMsF town: http://www.youtube.com/watch?v=g6RRKYf_Pd0
SMf locations module (Ogre). Game video: http://www.youtube.com/watch?v=ZlhBgPJhAxI
Post Reply