Re: MP3D Engine Alpha 30
Posted: Sat Jun 30, 2012 10:15 am
Menu: compiler -> compiler options. You will find a textfield called "Library Subsystem" here. Just type in "dx9" (there should be the same, if you open a demo file)
http://www.purebasic.com
https://www.purebasic.fr/english/
Code: Select all
MP_Graphics3D (640,480,0,1) ; Erstelle ein WindowsFenster #Window = 0
SetWindowTitle(0, "Vertex und Triangle Demo 2")
camera=MP_CreateCamera() ; Kamera erstellen
light=MP_CreateLight(2) ; Es werde Licht
Mesh = MP_CreateMesh() ; Erzeuge leeres Mesh
If CreateImage(0,128, 128) ; Erzeuge 6 unterschiedliche Texturseiten
Font = LoadFont(#PB_Any, "Arial" , 24)
StartDrawing(ImageOutput(0))
Box(0, 0, 64, 64,RGB(255,0,0))
Box(0, 64, 64, 64,RGB(255,255,0))
Box(64, 0, 64, 64,RGB(0,255,0))
Box(64, 64, 64, 64,RGB(0,0,255))
DrawingFont(FontID(Font))
DrawingMode(#PB_2DDrawing_Transparent)
DrawText(20,45,"MP3D",RGB(0,0,0))
StopDrawing() ; This is absolutely needed when the drawing operations are finished !!! Never forget it !
EndIf
Texture = MP_ImageToTexture(0) ; Create Texture from image
MP_EntitySetTexture (Mesh, Texture )
; Create 0 Vertex for middle
MP_AddVertex (Mesh, 0, 0,0,0,0.5,0.5)
For n = 0 To 360 Step 20
; Create 18 Vertexe
MP_AddVertex (Mesh, Sin (Radian(n)), Cos(Radian(n)),0,0,Sin (Radian(n))/2+0.5,-Cos(Radian(n))/2+0.5)
Next n
MP_AddTriangle (Mesh, 0,1,18)
MP_PositionEntity (Mesh,0,0,3)
While Not MP_KeyDown(#PB_Key_Escape) And Not WindowEvent() = #PB_Event_CloseWindow; Esc abfrage oder Windows Schliessen
count + 1
If count > 60 ; easy counter
count = 0
count2 + 1
If count2 < 18 ; add max 18 triangles
MP_AddTriangle (Mesh, 0,count2,count2+1)
EndIf
EndIf
; If count2 > 18 ; change x,y position of vertex
; For n = 0 To 20
; MP_VertexSetX (Mesh,n,MP_VertexGetX (Mesh,n)+Sin(count2+n)/100)
; MP_VertexSetY (Mesh,n,MP_VertexGetY (Mesh,n)+Cos(count2+n)/100)
; Next
; EndIf
MP_TurnEntity (Mesh,0,0,0.2)
MP_RenderWorld() ; Erstelle die Welt
MP_Flip () ; Stelle Sie dar
Wend
Code: Select all
;depends on MP_PickingTriangle.pb and MP_ChessShadow MP3D examples
Global xres=800, yres=600
MP_Graphics3D (xres,yres,0,3)
SetWindowTitle(0, "mesh eating, tearing and shadow, click on the green board to tear it")
camera=MP_CreateCamera()
light=MP_CreateLight(0)
MP_InitShadow()
Width=256
Height=256
;to make a background with gradient color
If CreateImage(0, Width, Height)
MP_CreateImageColored(0, 0, RGB(0,255,255), RGB(0,255,255), RGB(200,0,255), RGB(200,0,255))
EndIf
Surface = MP_ImageToSurface(0,0)
FreeImage(0)
MP_SurfaceSetPosition(Surface,0,0,1)
MP_SurfaceDestRect(Surface,0, 0, xres, yres)
texture = MP_CreateTextureColor(256, 256, RGBA(0, 255, 0, 0))
texture2 = MP_CreateTextureColor(256, 256, RGBA(0, 255, 255, 0))
texture3 = MP_CreateTextureColor(256, 256, RGBA(0, 0, 255, 255))
cone = MP_CreateCone(64, 10)
MP_EntitySetTexture(cone, texture2)
MP_PositionEntity(cone, 0, 2, 0)
MP_ScaleMesh(cone, 0.5, 0.5, 0.5)
MP_RotateEntity(cone, 0, 90, 0)
plane = MP_CreatePlane(10, 10)
MP_EntitySetTexture(plane, texture)
MP_RotateEntity(plane, 0, 0, 90)
plane2 = MP_CreatePlane(10, 10)
MP_EntitySetTexture(plane2, texture3)
MP_RotateEntity(plane2, 0, 90, 90)
cam0 = MP_CreateCamera()
MP_PositionCamera(cam0, -150, 90, -140)
MP_RotateCamera(cam0, 47, 0, -30)
MP_PositionEntity(light, 0, 20, 20)
MP_EntityLookAt(light,0,0,0)
While Not MP_KeyDown(#PB_Key_Escape) And Not WindowEvent() = #PB_Event_CloseWindow
count.f + 0.01
MP_PositionEntity(light, Sin(count+#PI/2) * 10 , 20, Cos(count+#PI/2) * 10)
MP_EntityLookAt(light,MP_EntityGetX(plane),MP_EntityGetY(plane),MP_EntityGetZ(plane))
MP_PositionCamera (Camera, 10, 5, 6)
MP_CameraLookAt(Camera,MP_EntityGetX(plane),MP_EntityGetY(plane),MP_EntityGetZ(plane))
;;0000000000000000000000000000000000000000000000000000
If MP_MouseButtonDown(0)
pickedmesh = MP_PickCamera(cam0, WindowMouseX(0),WindowMouseY(0))
triangleindex = MP_PickedGetTriangle();
If triangleindex And pickedmesh = plane
index0 = MP_EntityGetTriangle(pickedmesh, triangleindex, 0)
index1 = MP_EntityGetTriangle(pickedmesh, triangleindex, 1)
index2 = MP_EntityGetTriangle(pickedmesh, triangleindex, 2)
x1.f=MP_VertexGetX(pickedmesh, index1)
y1.f=MP_VertexGetY(pickedmesh, index1)
z1.f=MP_VertexGetZ(pickedmesh, index1)
x2.f=MP_VertexGetX(pickedmesh, index2)
y2.f=MP_VertexGetY(pickedmesh, index2)
z2.f=MP_VertexGetZ(pickedmesh, index2)
; reset the vertex1 coordinates the same as vertex2
MP_VertexSetX(plane,index1,x2)
MP_VertexSetY(plane,index1,y2)
MP_VertexSetZ(plane,index1,z2)
EndIf
EndIf
;;;00000000000000000000000000000000000000000000000000000
MP_RenderWorld()
MP_Flip ()
Wend
Code: Select all
;depends on MP_PickingTriangle.pb and MP_ChessShadow MP3D examples
Global xres=800, yres=600
MP_Graphics3D (xres,yres,0,3)
SetWindowTitle(0, "mesh eating, tearing and shadow, click on the green board to tear it")
camera=MP_CreateCamera()
light=MP_CreateLight(0)
MP_InitShadow()
Width=256
Height=256
;to make a background with gradient color
If CreateImage(0, Width, Height)
MP_CreateImageColored(0, 0, RGB(0,255,255), RGB(0,255,255), RGB(200,0,255), RGB(200,0,255))
EndIf
Surface = MP_ImageToSurface(0,0)
FreeImage(0)
MP_SurfaceSetPosition(Surface,0,0,1)
MP_SurfaceDestRect(Surface,0, 0, xres, yres)
texture = MP_CreateTextureColor(256, 256, RGBA(0, 255, 0, 0))
texture2 = MP_CreateTextureColor(256, 256, RGBA(0, 255, 255, 0))
texture3 = MP_CreateTextureColor(256, 256, RGBA(0, 0, 255, 255))
cone = MP_CreateCone(64, 10)
MP_EntitySetTexture(cone, texture2)
MP_PositionEntity(cone, 0, 2, 0)
MP_ScaleMesh(cone, 0.5, 0.5, 0.5)
MP_RotateEntity(cone, 0, 90, 0)
plane = MP_CreateMesh() ;the plane we want to make holes
plane2 = MP_CreatePlane(10, 10)
MP_EntitySetTexture(plane2, texture3)
MP_RotateEntity(plane2, 0, 90, 90)
cam0 = MP_CreateCamera()
MP_PositionCamera(cam0, -150, 90, -140)
MP_RotateCamera(cam0, 47, 0, -30)
MP_PositionEntity(light, 0, 20, 20)
MP_EntityLookAt(light,0,0,0)
;;00000000000000000000000000000000000000000000000000000
; constructing the green board
i.l:j.l:vtx.l=-1:t1.f=0:t2.f=0:t3.f=0
Restore Vertices
For i=0 To 17
vtx + 1 ; corner 0 of every triangle
For j=0 To 2
Read.f t1 : Read.f t2 : Read.f t3
MP_AddVertex(plane,t1, t2, t3)
Next j
MP_AddTriangle (plane, vtx,vtx+1,vtx+2)
vtx+2
Next i
MP_ScaleMesh(plane, 2.5, 2.5, 2.5)
MP_EntitySetTexture(plane, texture)
MP_PositionEntity (plane,-3,0,0)
;-00000000000000000000000000000000000000000000000000000
While Not MP_KeyDown(#PB_Key_Escape) And Not WindowEvent() = #PB_Event_CloseWindow
count.f + 0.01
MP_PositionEntity(light, Sin(count+#PI/2) * 10 , 20, Cos(count+#PI/2) * 10)
MP_EntityLookAt(light,MP_EntityGetX(plane),MP_EntityGetY(plane),MP_EntityGetZ(plane))
MP_PositionCamera (Camera, 10, 5, 6)
MP_CameraLookAt(Camera,MP_EntityGetX(plane),MP_EntityGetY(plane),MP_EntityGetZ(plane))
;;0000000000000000000000000000000000000000000000000000
If MP_MouseButtonDown(0)
pickedmesh = MP_PickCamera(cam0, WindowMouseX(0),WindowMouseY(0))
triangleindex = MP_PickedGetTriangle();
If triangleindex And pickedmesh = plane
index0 = MP_EntityGetTriangle(pickedmesh, triangleindex, 0)
index1 = MP_EntityGetTriangle(pickedmesh, triangleindex, 1)
index2 = MP_EntityGetTriangle(pickedmesh, triangleindex, 2)
x1.f=MP_VertexGetX(pickedmesh, index1)
y1.f=MP_VertexGetY(pickedmesh, index1)
z1.f=MP_VertexGetZ(pickedmesh, index1)
x2.f=MP_VertexGetX(pickedmesh, index2)
y2.f=MP_VertexGetY(pickedmesh, index2)
z2.f=MP_VertexGetZ(pickedmesh, index2)
; reset the vertex1 coordinates the same as vertex2
MP_VertexSetX(plane,index1,x2)
MP_VertexSetY(plane,index1,y2)
MP_VertexSetZ(plane,index1,z2)
EndIf
EndIf
;;;00000000000000000000000000000000000000000000000000000
MP_RenderWorld()
MP_Flip ()
Wend
DataSection
Vertices:
Data.f 0,3,0
Data.f 1,2,0
Data.f 1,3,0
Data.f 0,3,0
Data.f 0,2,0
Data.f 1,2,0
Data.f 1,3,0
Data.f 2,2,0
Data.f 2,3,0
Data.f 1,3,0
Data.f 1,2,0
Data.f 2,2,0
Data.f 2,3,0
Data.f 3,2,0
Data.f 3,3,0
Data.f 2,3,0
Data.f 2,2,0
Data.f 3,2,0
Data.f 0,2,0
Data.f 1,1,0
Data.f 1,2,0
Data.f 0,2,0
Data.f 0,1,0
Data.f 1,1,0
Data.f 1,2,0
Data.f 2,1,0
Data.f 2,2,0
Data.f 1,2,0
Data.f 1,1,0
Data.f 2,1,0
Data.f 2,2,0
Data.f 3,1,0
Data.f 3,2,0
Data.f 2,2,0
Data.f 2,1,0
Data.f 3,1,0
Data.f 0,1,0
Data.f 1,0,0
Data.f 1,1,0
Data.f 0,1,0
Data.f 0,0,0
Data.f 1,0,0
Data.f 1,1,0
Data.f 2,0,0
Data.f 2,1,0
Data.f 1,1,0
Data.f 1,0,0
Data.f 2,0,0
Data.f 2,1,0
Data.f 3,0,0
Data.f 3,1,0
Data.f 2,1,0
Data.f 2,0,0
Data.f 3,0,0
EndDataSection
Code: Select all
;depends on MP_PickingTriangle.pb and MP_ChessShadow MP3D examples
Global xres=800, yres=600
MP_Graphics3D (xres,yres,0,3)
SetWindowTitle(0, "press R to rotate")
;MP_Wireframe(1)
camera=MP_CreateCamera()
light=MP_CreateLight(2)
MP_PositionEntity(light, 10 , 20, -1)
;MP_InitShadow(1)
Width=256
Height=256
texture = MP_LoadTexture("texture.png")
sphere = MP_CreateSphere(30)
;sphere = MP_LoadMesh("model.x")
MP_EntitySetTexture(sphere, texture)
MP_ScaleMesh(sphere, 4, 4,4)
MP_RotateEntity(sphere, 180, 0, 0)
cam0 = MP_CreateCamera()
MP_PositionCamera(cam0, -150, 90, -140)
MP_RotateCamera(cam0, 47, 0, -30)
rot.l=0
MP_RotateEntity(sphere, rot, 0, 0)
While Not MP_KeyDown(#PB_Key_Escape) And Not WindowEvent() = #PB_Event_CloseWindow
MP_PositionCamera (Camera, 10, 5, 6)
MP_CameraLookAt(Camera,MP_EntityGetX(plane),MP_EntityGetY(plane),MP_EntityGetZ(plane))
If MP_KeyDown(#PB_Key_R)
rot + 1
MP_RotateEntity(sphere, rot, 0, 0)
EndIf
If MP_MouseButtonDown(0)
If key = 0
pickedmesh = MP_PickCamera(cam0, WindowMouseX(0),WindowMouseY(0))
triangleindex = MP_PickedGetTriangle();
If triangleindex; And pickedmesh = plane
MP_FreeTriangle(pickedmesh, triangleindex)
key = 1
EndIf
EndIf
EndIf
If MP_MouseButtonUp(0)
key = 0
EndIf
MP_RenderWorld()
MP_Flip ()
Wend
MP_SaveMesh("model.x",sphere)
Code: Select all
Global xres=800, yres=600
MP_Graphics3D (xres,yres,0,3)
SetWindowTitle(0, "")
;MP_Wireframe(1)
camera=MP_CreateCamera()
light=MP_CreateLight(2)
MP_PositionEntity(light, 10 , 20, -1)
;MP_InitShadow(1)
texture = MP_LoadTexture("texture.png")
sphere = MP_LoadMesh("model.x")
MP_EntitySetTexture(sphere, texture)
MP_ScaleMesh(sphere, 1, 1,1)
MP_RotateEntity(sphere, 180, 0, 0)
cam0 = MP_CreateCamera()
MP_PositionCamera(cam0, -150, 90, -140)
MP_RotateCamera(cam0, 47, 0, -30)
While Not MP_KeyDown(#PB_Key_Escape) And Not WindowEvent() = #PB_Event_CloseWindow
MP_PositionCamera (Camera, 10, 5, 6)
MP_CameraLookAt(Camera,MP_EntityGetX(plane),MP_EntityGetY(plane),MP_EntityGetZ(plane))
If MP_KeyDown(#PB_Key_R)
rot + 1
MP_RotateEntity(sphere, rot, 0, 0)
EndIf
MP_TurnEntity(sphere, 0.5, 0, 0)
MP_RenderWorld()
MP_Flip ()
Wend
Code: Select all
;////////////////////////////////////////////////////////////////
;//
;// Project Title: MP 3D Engine
;// File Title: Bewegende Objekte2.pb
;// Created On: 26.11.2008
;// Updated On:
;// Author: Michael Paulwitz
;// OS:Windows
;//
;// Teapot is changed
;// Teekanne wird verنndert
;//
;////////////////////////////////////////////////////////////////
;-
;- ProgrammStart
MP_Graphics3D (640,480,0,3) ; Erstelle ein WindowsFenster #Window = 0
SetWindowTitle(0, "Teapot is changed") ; So soll es heissen
camera=MP_CreateCamera() ; Kamera erstellen
x.f=0 : y.f=0 : z.f = -4
MP_PositionCamera(camera,x.f,y.f,z.f) ; Kameraposition
light=MP_CreateLight(1) ; Es werde Licht
cube=MP_CreateTeapot() ; Nen Würfel
;cube=MP_Create3DText ("Times", "MP 3D Engine", 30) ; Oder 3D schrift
For n = 0 To MP_CountVertices(cube)-1
farbea.l = Random(255)
farbeb.l = Random(255)
farbec.l = Random(255)
MP_VertexSetColor (cube,n,RGB(farbea,farbeb,farbec))
Next
StartTime = ElapsedMilliseconds()
While Not MP_KeyDown(#PB_Key_Escape) And Not WindowEvent() = #PB_Event_CloseWindow; Esc abfrage oder schliessen
For n = 0 To MP_CountVertices(cube)-1
x.f = MP_VertexGetX (cube,n)
y.f = MP_VertexGetY (cube,n)
z.f = MP_VertexGetZ (cube,n)
zufall.f = (Random (1000)-500)/100000
MP_VertexSetX (cube,n, x + zufall)
MP_VertexSetY (cube,n, y + zufall)
MP_VertexSetZ (cube,n, z + zufall)
Next
ElapsedTime = ElapsedMilliseconds()-StartTime
If ElapsedTime >= 10000
MP_SaveMesh("teapot.x",cube)
break
EndIf
MP_DrawText (10,10,"Lنuft mit "+Str(MP_FPS ())+" FPS") ; Textanzeige an Position x,y, Farbe RGB und Text$
MP_TurnEntity (cube,0.05,0.5,1) ; Würfel Drehen
MP_RenderWorld () ; Hier gehts los
MP_Flip () ;
Wend
End