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 »

Thanks Michael, the new cylinder needs float type for rad1 rad2 like the hight.f. so i can't translate the code correctly. as an example
Mesh2=MP_CreateCylinder(10,4, 0.4, 2) ; new Cylinder with options
will make a sharp tip cone because it decipher 0.4 as zero

i am still looking how to parallel between
;glRotatef_( openangle,0,0,1)
MP_RotateMesh(cyl, 0,0,openangle)
;glRotatef_(twist,0,1,0)
MP_RotateMesh(cyl, 0,twist,0)
i will adopt the strategy of using MP_AddMesh , this is the easiest approach, but needs to accommodate rotations correctly
here is the very crude approximate which show only the very general strategy, and not a correct version:

Code: Select all

Declare DrawBranch( startRadius.f, startlength.f, levels.l, openangle.f, twist.f)

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, "press '1' or '2' to change Camera view position")

camera = MP_CreateCamera() ; Kamera erstellen

light= MP_CreateLight(2)    ; Es werde Licht
MP_PositionEntity(light, -10, 10, 0)
MP_AmbientSetLight (RGB(0,100,200))

cam = MP_CreateCamera()

MP_PositionEntity(cam, 0, 3, -7)
MP_EntityLookAt(cam, 0, 0, 0)

tex0 = MP_CreateTextureColor(128, 128, RGBA(0, 255, 0, 0))
MP_MaterialEmissiveColor(tex0, 0, 122, 132, 132)
tex1 = MP_CreateTextureColor(128, 128, RGBA(25, 255, 255, 0))
MP_MaterialEmissiveColor(tex1, 0, 122, 132, 132)

;mp_wireframe(1)     

Global tree = MP_CreateCylinder(8,3,1, 2)
MP_ResizeMesh(tree,0.1,0.1,0.1)
DrawBranch(1, 2, 6, 30,30) 

MP_EntitySetTexture(sphere, tex1)

MP_EntitySetNormals (sphere)
MP_MaterialDiffuseColor (sphere,255,255,255,50)
MP_MaterialSpecularColor (sphere, 255, 255 ,255, 155,5)
;;oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo

While Not MP_KeyDown(#PB_Key_Escape) And Not WindowEvent() = #PB_Event_CloseWindow; Esc abfrage oder Windows Schliessen
  If MP_KeyHit(#PB_Key_1) 
    MP_PositionEntity(cam, 0, 10, -3)
    MP_EntityLookAt(cam, 0, 0, 0)
ElseIf MP_KeyHit(#PB_Key_2) 
  MP_PositionEntity(cam, 0, 3, -7)
  MP_EntityLookAt(cam, 0, 0, 0)
EndIf

MP_TurnEntity (tree,-2,-1,1) ; mee too
 MP_RenderWorld() ; Erstelle die Welt
 MP_Flip () ; Stelle Sie dar
     
Wend

End

Procedure DrawBranch( startRadius.f, startlength.f, levels.l, openangle.f, twist.f)
  
  baseRadius.f = startRadius
    topRadius.f = baseRadius - startRadius/levels
    length.f = startlength
    
 ;glPushMatrix_()
 For i = 1 To levels
     
     cyl=MP_CreateCylinder(8,length,baseRadius, topRadius)
     MP_RotateMesh(cyl, -90,0,0)
     MP_TranslateMesh(cyl, 0,  length, 0)
          
     ;glRotatef_( openangle,0,0,1)
     MP_RotateMesh(cyl, 0,0,openangle)
     ;glRotatef_(twist,0,1,0)
     MP_RotateMesh(cyl, 0,twist,0)
        
     ;glPushMatrix_();
        
     ;glRotatef_(-openangle*2,0,0,1)
     MP_RotateMesh(cyl, 0,0,-openangle*2)
     MP_AddMesh(cyl , tree) : MP_FreeEntity(cyl)
        
          If i = 1 
            DrawBranch(topRadius, length, levels-1, -openangle, twist)
          Else
            DrawBranch(topRadius,  length, levels-i, openangle, twist)
          EndIf  
            
      ;glPopMatrix_()

        baseRadius = topRadius
        topRadius = baseRadius - startRadius/levels 
        length = length - startlength/levels

      Next  
    ;glPopMatrix_()

  EndProcedure

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 »

WoW!
Still no time to test it.
I spect will do tomorrow.

Thanks ! :D :!: :!:

BTW:
glRotatef_( openangle,0,0,1) should be equivalent to:
MP_RotateMesh(cyl, 0,0,openangle)
Is not it?
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 applePi,

i am sorry my mistake. The command MP_CreateCylinder has now two float parameters
MP_CreateCylinder(Segmente,h.f[,Rad1.f,Rad2.f])

I have actualized all libs, includes the following:

32 Bit MP3D_lib for PureBasic\SubSystems\dx9\purelibraries\userlibraries\
http://www.flasharts.de/mpz/mp33_beta/d ... ibrary.zip

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 »

Hi Michael
it is still not working. here your example
Mesh2=MP_CreateCylinder(10,6, 0.4 ,2)
using 0.4 results in sharp cone. using 0.5 results suddenly in the smaller radius = 1
the link http://www.flasharts.de/mpz/mp33_beta/d ... ibrary.zip does not go any where

Code: Select all

MP_Graphics3D (640,480,0,3) ; Create a Window with 3D function #Window = 0
SetWindowTitle(0, "3D with two cylinders") 

camera=MP_CreateCamera() ; camera on

light=MP_CreateLight(1) ; yes light

;Mesh1=MP_CreateCylinder(10,3) ; my Cylinder normal

Mesh2=MP_CreateCylinder(10,6,0.4,2) ; my Cylinder with options


;MP_PositionEntity (Mesh1,-3,0,8) ; Position mesh1

MP_PositionEntity (Mesh2,0,0,8) ; Position mesh2

While Not MP_KeyDown(#PB_Key_Escape) And Not WindowEvent() = #PB_Event_CloseWindow; Esc abfrage oder Windows Schliessen
  
    ;MP_TurnEntity (Mesh1,2,1,1) ; go to moving
    MP_TurnEntity (Mesh2,-2,-1,1) ; mee too
    
    MP_RenderWorld() ; render the world
    MP_Flip () ; show me the world
    
Wend
take your time as i need first to study smaller examples to see how rotation in opengl and mp3d related .
applePi
Addict
Addict
Posts: 1404
Joined: Sun Jun 25, 2006 7:28 pm

Re: MP3D Engine Alpha 32

Post by applePi »

Psychophanta wrote:
glRotatef_( openangle,0,0,1) should be equivalent to:
MP_RotateMesh(cyl, 0,0,openangle)
Is not it?
in this specific question and with relation to the following code it seems the cylinder in opengl it rotates clockwise, while in mp3d anticlockwise. and also it depends from where the camera positioned and looking at.
look this cylinder demo written by Michael, comment and uncomment lines of

Code: Select all

  MP_TurnEntity (Mesh2,0.9, 0, 0) 
  ;MP_TurnEntity (Mesh2,0, 0.9, 0) 
  ;MP_TurnEntity (Mesh2,0, 0, 0.9)  
and compare with Opengl

Code: Select all

glRotatef_(XRot, 1, 0, 0)
  ;glRotatef_(YRot, 0.0, 1.0, 0.0)
  ;glRotatef_(ZRot, 0, 0, 1)
note also that the opengl cylinder have a small radius side (not spike) and big radius while in mp3d until now have spike and big radius side

needs the latest mp3d (look above): this is Michael code:

Code: Select all

MP_Graphics3D (800,600,0,3) ; Create a Window with 3D function #Window = 0
SetWindowTitle(0, "3D with two cylinders") 

camera=MP_CreateCamera() ; camera on

light=MP_CreateLight(1) ; yes light

;Mesh1=MP_CreateCylinder(10,3) ; old Cylinder normal

Mesh2=MP_CreateCylinder(10,6,0.4,2) ; new Cylinder with options

;MP_PositionEntity (Mesh1,-3,0,8) ; Position mesh1

MP_PositionEntity (Mesh2,0,0,14) ; Position mesh2

While Not MP_KeyDown(#PB_Key_Escape) And Not WindowEvent() = #PB_Event_CloseWindow; Esc abfrage oder Windows Schliessen
  ;MP_RotateEntity(Mesh2, -90, 0, 0 )
  MP_TurnEntity (Mesh2,0.9, 0, 0) 
  ;MP_TurnEntity (Mesh2,0, 0.9, 0) 
  ;MP_TurnEntity (Mesh2,0, 0, 0.9) 
    
    MP_RenderWorld() ; render the world
    MP_Flip () ; show me the world
    
Wend
opengl textured transparent cylinder (tested in pb 541)

Code: Select all

UseJPEGImageDecoder()
UsePNGImageDecoder()

Define.l i, Event, key, quit, t
Define Rot.f

#ImagePath = #PB_Compiler_Home + "examples/3d/Data/Textures/"

Dim *Buffer(6)

For i=1 To 6
  Select i
      Case 1
        LoadImage(i, #ImagePath+"Geebee2.bmp")
        Case 2
          LoadImage(i, #ImagePath+"Wood.jpg")
          Case 3
            LoadImage(i, #ImagePath+"ValetCoeur.jpg")
            Case 4
              LoadImage(i, #ImagePath+"MRAMOR6X6.jpg")
              Case 5
                LoadImage(i, #ImagePath+"ogrelogo-small.jpg")
                Case 6
                  LoadImage(i, #ImagePath+"clouds.jpg")
   EndSelect 
   *Buffer(i) = EncodeImage(i)
Next

Dim TexID(6)

OpenWindow(0, 0, 0, 800, 600, "OpenGL demo .. Transparent Textured Cylinder")
SetWindowColor(0, 0)
OpenGLGadget(0, 0, 0, WindowWidth(0) , WindowHeight(0), #PB_OpenGL_Keyboard)

Global qobj = gluNewQuadric_();
gluQuadricDrawStyle_(qobj, #GL_FILL); /* smooth shaded */
gluQuadricNormals_(qobj, #GL_SMOOTH);
gluQuadricTexture_(qobj, #GL_TRUE ) 
glEnable_(#GL_NORMALIZE);

; ----- Generate texture
For i = 1 To 6
glGenTextures_(1, @TexID(i))
glBindTexture_(#GL_TEXTURE_2D, TexID(i))
glTexParameteri_(#GL_TEXTURE_2D, #GL_TEXTURE_MIN_FILTER, #GL_LINEAR)
glTexParameteri_(#GL_TEXTURE_2D, #GL_TEXTURE_MAG_FILTER, #GL_LINEAR)
glTexImage2D_(#GL_TEXTURE_2D, 0, 3, ImageWidth(i), ImageHeight(i), 0, #GL_BGR_EXT, #GL_UNSIGNED_BYTE, *Buffer(i)+57)
Next

For i=1 To 6
  FreeMemory(*Buffer(i))
Next

glMatrixMode_(#GL_PROJECTION)
glLoadIdentity_() ;Reset The Projection Matrix
gluPerspective_(30.0, Abs(WindowWidth(0) / WindowHeight(0)), 0.1, 500.0)
gluLookAt_( 0, 0, -50,   ; camera positioned in 0,5,0 looking at 0,0,-7.5
            0, 0, 0,
            0, 1, 0 ) 
glMatrixMode_(#GL_MODELVIEW)
glLoadIdentity_() ;Reset The Modelview Matrix
glColor4f_(1.0,1.0,1.0,  0.50) ;Full Brightness. 50% Alpha ( NEW )
glBlendFunc_(#GL_SRC_ALPHA,#GL_ONE) ;Blending Function For Translucency Based On Source Alpha Value ( NEW )
 
SetActiveGadget(0) ; make the openGLgadget active
Repeat
  Event = WindowEvent()
  XRot.f + 0.7
  YRot.f + 0.7
  ZRot.f + 0.7
  ;glEnable_(#GL_CULL_FACE) 

  glClear_(#GL_COLOR_BUFFER_BIT | #GL_DEPTH_BUFFER_BIT)   ; Clear screen and depth buffer
  glLoadIdentity_()                                       ; Reset current modelview matrix
  glTranslatef_(0.0, 0.0, 7.5)
  ;glRotatef_(-90, 1, 0, 0)
  glRotatef_(XRot, 1, 0, 0)
  ;glRotatef_(YRot, 0.0, 1.0, 0.0)
  ;glRotatef_(ZRot, 0, 0, 1)
  glEnable_(#GL_TEXTURE_2D)                               ; Enable texture mapping 
  glEnable_(#GL_BLEND);
  glDisable_(#GL_DEPTH_TEST)
  
  glBindTexture_(#GL_TEXTURE_2D, TexID(1))  ; Start drawing the cube
 ;gluCylinder(GLUquadric* quad, GLdouble	base, GLdouble 	top, GLdouble height, GLint slices, GLint stacks)
  gluCylinder_(qobj, 0.3 , 3, 10, 8, 8); 8,8: slices, stacks
  
  
  If Event = #PB_Event_Gadget And EventGadget() = 0 
   If EventType() = #PB_EventType_KeyDown ; like KeyboardPush
            key = GetGadgetAttribute(0,#PB_OpenGL_Key )
            If key = #PB_Shortcut_Escape ;  Esc key to exit
               quit = 1
            EndIf  
    EndIf
  EndIf
   SetGadgetAttribute(0, #PB_OpenGL_FlipBuffers, #True)
   Delay(10)
Until Event = #PB_Event_CloseWindow Or quit = 1
For i=1 To 6
      glDeleteTextures_(1, @TexID(i))
Next
 
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 applePi,

the problem with the 0.4 < for Rad1/Rad2 is a problem of the D3DXCreateCylinder command. I have solved this and you can use the Rad1.f until 0.05. I think this must solve the problem.

I have actualized the libs, include:

32 Bit MP3D_lib for PureBasic\SubSystems\dx9\purelibraries\userlibraries\
http://www.flasharts.de/mpz/mp33_beta/d ... ibrary.zip

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 »

Great Michael, thank you very much. the above quoted cylinder example show the small 0.4 radius and even much below than that
now we can use the new cylinder for making shapes of all kinds.
best wishes
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 »

Great samples of opengl applePi.
Thanks for the big update Michael. I think it is time to quit the "alpha" suffix :)

About rotations and turnings of entities and meshes:

I have had a conversation with Michael via email about this.
The matter is that any rotation or turning should be like the "right hand rule":
Image
The arrow is intended to point to the positive semiaxis of the X, Y or Z axis, so the item should rotate as this rule, i.e., clockwise while watching from the negative part of X, Y or Z axis to the positive one.

The fact is that now in MP3D this rule is same for all the 3 axis but just opposit to that "right hand rule", i.e., anti-clockwise.
Michael told me that will not change it and really is not an inconvenience, just because the used rule IS THE SAME for the 3 axis.

I have seen that opengl is worse, because the "right hand rule" is performed for Y, and Z axis (everytime positive semiaxis are screen-up for Y axis and screen-forward for Z one), but for X axis is opposit, and this is really a serious inconvenience, because opengl seems not use the same rule for the 3 axes.

Apart of all that: to express an angle value in a n-dimension world (3 or more dimensions) is enough A UNIQUE VECTOR, so, in 3D world there is only needed 3 scalar values to signify a complete angle value (for rotation, for turning, or whatever), but opengl uses 4 scalar parameters to signify an angle value, instead to use just 3, which should the correct way.
Inside the DX-3D and inside the opengl is used rotation matrixes and homogeneous transformation matrixes to perform every translation, rotation, deformation, etc, but the functions which uses angles should have 3 scalar parameters per angle, and no more than 3.


Thanks!
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 Psychophanta,

i have looked on the "left hand rule" and "right hand rule" and checked it in my lib. Now the lib can both rules. I have included the
MP_RightHandOn(1) command for "right hand rule". Please test this. i hope i found all left an right hand functions to patch them...

32 Bit MP3D_lib for PureBasic\SubSystems\dx9\purelibraries\userlibraries\
http://www.flasharts.de/mpz/mp33_beta/d ... ibrary.zip

P.S: But it is important to use the comand on the beginning. The camera will be created as a "left" or "right" hand rules camera.

Code: Select all

MP_Graphics3D (640,480,0,3) ; Create a Window with 3D function #Window = 0
SetWindowTitle(0, "3D with two cylinders") 

MP_RightHandOn(1)

camera=MP_CreateCamera() ; camera on

light=MP_CreateLight(1) ; yes light

Mesh1=MP_CreateCylinder(10,3) ; my Cylinder normal

Mesh2=MP_CreateCylinder(10,3,0.2,1.2) ; my Cylinder with options

MP_PositionEntity (Mesh1,-3,0,8) ; Position mesh1

MP_PositionEntity (Mesh2,3,0,8) ; Position mesh2

While Not MP_KeyDown(#PB_Key_Escape) And Not WindowEvent() = #PB_Event_CloseWindow; Esc abfrage oder Windows Schliessen
  
    MP_TurnEntity (Mesh1,0,1,0) ; go to moving
    MP_TurnEntity (Mesh2,0,-1,0) ; mee too
    
    a + 1
    If a = 100
      MP_RightHandOn(1)
    EndIf 
    
    MP_RenderWorld() ; render the world
    MP_Flip () ; show me the world
    
Wend

and here with tricky code

Code: Select all

MP_Graphics3D (640,240,0,3) ; Erstelle ein WindowsFenster mit 3D Funktion #Window = 0
SetWindowTitle(0, "2 Cameras left and right handelt") ; Setzt einen Fensternamen

camera1=MP_CreateCamera() ; Kamera erstellen
camera2=MP_CreateCamera() ; Kamera erstellen (Orthoview)

light=MP_CreateLight(1) ; Es werde Licht

Mesh=MP_CreateCube() ; Und jetzt ein TeaPot

MP_PositionEntity(camera1,0,0,-3)
MP_PositionEntity(camera2,0,0,-3)

BackColor1 = RGB(0,0,123)
BackColor2 = RGB(0,66,123)

MP_CameraSetPerspective(camera1,45,1.33)
MP_RightHandOn(1) ; Change the camera2 to right hand rule
MP_CameraSetPerspective(camera2,45,1.33)


camera5 = MP_CameraViewPort (camera1,0,0,640/2,240,BackColor1)
camera6 = MP_CameraViewPort (camera2,640/2,0,640/2,240,BackColor2)

While Not MP_KeyDown(#PB_Key_Escape) And Not WindowEvent() = #PB_Event_CloseWindow; Esc abfrage oder Windows Schliessen

    MP_TurnEntity (Mesh,0.1,0.1,0.1) ; dreh den Würfel
    MP_RenderWorld () ; Hier gehts los
    MP_Flip ()   

Wend
Greetings Michael
Working on - MP3D Library - PB 5.73 version ready for download
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 »

Thanks Michael, but i think that is not a good idea.
In my opinion this new command complicates things.
There was good before, no problem.
http://www.zeitgeistmovie.com

while (world==business) world+=mafia;
applePi
Addict
Addict
Posts: 1404
Joined: Sun Jun 25, 2006 7:28 pm

Re: MP3D Engine Alpha 32

Post by applePi »

thank you Psychophanta for the info and Michael for the exceptional work.
regarding the MP_RightHandOn, in fact i can't decide an opinion now, but i have saved the MP_RightHandOn Library for possible future usage , don't know. it is possible the MP_RightHandOn Library can be available as an independent file other than the normal Library file.
now in the MP_RotateEntity Doc : 1 local, 0 world
but look this example (your example about the new cylinder)

Code: Select all

MP_RotateEntity(Mesh, 0, 45, 0 ,1  )  ; last parameter 1 local, 0 world
MP_RotateEntity(Mesh, 0, 45, 0 ,1 )
the cylinder stay at 45 while i think should go to 90 degree, if we consider local as relative rotation

on the other hand :

Code: Select all

MP_RotateMesh(Mesh, 0, 45, 0 )
MP_RotateMesh(Mesh, 0, 45, 0 )
;MP_RotateMesh(Mesh, 0, 45, 0 )
will go correctly to 90. and if we comment the third line will continue to 135 degree .
in the Doc said : relative angle

my request:
1- is possible for MP_RotateMesh to have also absolute angle (relative to the world ) in addition to its current relative rotational angle default option
2- is it available the possibility that the cylinder can have open sides, ie its smaller radius and bigger radius sides are open so we can use it as a tube in addition to its usual usage.

Code: Select all

MP_Graphics3D (800,600,0,3) ; Create a Window with 3D function #Window = 0
SetWindowTitle(0, "3D with two cylinders") 

camera=MP_CreateCamera() ; camera on

light=MP_CreateLight(1) ; yes light
MP_PositionEntity (light, 0, 10,0)
MP_EntityLookAt(light, 0,0,0)


Mesh=MP_CreateCylinder(10,25, 0.4,2) ; new Cylinder with options


MP_PositionEntity (Mesh,0,0,0) ; Position mesh2
MP_PositionEntity (camera, 0, 50,-1)
MP_EntityLookAt(camera, 0,0,0)

MP_RotateEntity(Mesh, 0, 45, 0 ,1  )  ; 1 local, 0 world
MP_RotateEntity(Mesh, 0, 45, 0 ,1 )
;MP_RotateEntity(Mesh, 0, 45, 0 ,1 )
  
;MP_RotateMesh(Mesh, 0, 45, 0 )
;MP_RotateMesh(Mesh, 0, 45, 0 )
;MP_RotateMesh(Mesh, 0, 45, 0 )

While Not MP_KeyDown(#PB_Key_Escape) And Not WindowEvent() = #PB_Event_CloseWindow; Esc abfrage oder Windows Schliessen
  ;MP_RotateEntity(Mesh, 0, 45, 0 ,0  )  ; 1 local, 0 world
  ;MP_RotateEntity(Mesh, 0, 45, 0 ,1 )
  ;MP_RotateEntity(Mesh, 0, 45, 0 ,1 )
  
  
  ;MP_TurnEntity (Mesh,0.9, 0, 0) 
  ;MP_TurnEntity (Mesh,0, 0.9, 0) 
  ;MP_TurnEntity (Mesh,0, 0, 0.9) 
    
    MP_RenderWorld() ; render the world
    MP_Flip () ; show me the world
    
Wend
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 »

Hi applePi,

I agree to your request '2'.

As long as i know:
MP_RotateMesh() is always absolute, this is, referred to world axis. So no needed your request '1'. However it is referred to the current shape (mesh), so , in some way, MP_RotateMesh() should be named as MP_TurnMesh()
When you perform MP_RotateMesh(mesh,0,45,0) one time, you are relocating all its vertex and faces, so, you are indeed rebulding a new mesh rotating its vertex,etc. from its current location.
And if you perform MP_RotateMesh(mesh,0,45,0) one more time, then you are taking the previous shape (vertex, faces, etc.) and relocating again, rotating one more time from its current location.
So the result will be the same that do: MP_RotateMesh(mesh,0,90,0) one time.

MP_RotateEntity() last parameter does not mean relative , but local, this is, i think it is referred to possible parent orientation; if no parent, then there is interpreted as global axises. (Michael: Correct me if i am wrong).
So, since last parameter is not related to the current orientation of the entity, there has no sense to repeat the same MP_RotateEntity(Mesh,0,45 0,1) command twice.

Regards!
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 Psychophanta you description is well. One roation to the world an one rotation for the local (Entity) world. You need the "local" rotation foo example for a camera or parent-slave and then you can follow the local camera word with local steps or turns. If you have "only" a global world you must calculate every movement to folow the camera...

MP3D has the lefthand rule only because i loved the blitzbasic 3D and i wanted to create a 3d lib like Blitzbasic 3d in dx9 for Purebasic. The MP_RightHandOn comand is only if you want to translate a ogre example, because Ogre has the right hand rule.


Question 2) The D3DXCreateCylinder() dx9 comand can only create a cylinder with two sides. We need a mesh creating code for a tube. If you find a c, c++ or Ogre example or something else to create a tube mesh i can make a MP_Tube command from them.

Greetings Michael
Working on - MP3D Library - PB 5.73 version ready for download
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 »

Is there a strategy to know the 3 vertex of any concrete triangle?
I wrote this where can be deleted the selected triangle, but how to select a vertex?

Code: Select all

MP_Graphics3D(640,480,0,3)
SetWindowTitle(0,"Mapping")
camera=MP_CreateCamera()
MP_PositionEntity(camera,0,0,-4)
luz=MP_CreateLight(1)

MP_Wireframe(1)
shape=MP_CreateCylinder(10,2)
tex.i=MP_CreateTextureColor(8,8,$00aaaaaa):MP_EntitySetTexture(shape,tex)
vertices.i=MP_CountVertices(shape)
triangles.i=MP_CountTriangles(shape)
While MP_KeyDown(#PB_Key_Escape)=0 And WindowEvent()<>#PB_Event_CloseWindow
  If MP_MouseButtonDown(1)
    MP_RotateMesh(shape,-MP_MouseDeltaY()/4,-MP_MouseDeltaX()/4,0)
  Else
    Meshfound=MP_PickCamera(camera,WindowMouseX(0),WindowMouseY(0))
    If Meshfound    
      MP_DrawText(0,0,"Mesh "+Str(MP_PickedGetEntity())+", Triangle: "+Str(MP_PickedGetTriangle()),0,$eeeeeeee)
      If MP_MouseButtonDown(0)
        MP_FreeTriangle(Meshfound,MP_PickedGetTriangle())
        vertices.i=MP_CountVertices(shape)
        triangles.i=MP_CountTriangles(shape)
      EndIf
    EndIf
  EndIf
  MP_DrawText(0,20,"Vertices: "+Str(vertices),0,$eeeeeeee)
  MP_DrawText(0,40,"Triangles: "+Str(triangles),0,$eeeeeeee)
  MP_RenderWorld()
  MP_Flip():Delay(12)
Wend
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,

i found in the PB Forum a Demo from DK_Peter how to create a tube with ogre. I "translated" the code to m3d and found a problem in MP_AddVertex and MP_AddTriangle (it crashed with my translated code). I have found the problem and now i have made a new working lib:

http://www.flasharts.de/mpz/mp33_beta/d ... ibrary.zip

If the code works fine i a can make a fast MP3d comand from them...

@Psychophanta, i am sorry there is no command to select a vertex. You can only go step by step from one vertex to another vertex...

Greetings Michael

Code: Select all

Structure Vector3
    x.f
    y.f
    z.f
EndStructure

Procedure Normalize(*V.Vector3)
    Define.f magSq, oneOverMag
     
    magSq = *V\x * *V\x + *V\y * *V\y + *V\z * *V\z
    If magsq > 0
      oneOverMag = 1.0 / Sqr(magSq)
      *V\x * oneOverMag
      *V\y * oneOverMag
      *V\z * oneOverMag
    EndIf
 EndProcedure
 
 
 Procedure CreateTube(outerRadius.f, innerRadius.f, height.f, numSegBase=16, numSegHeight=1)
     
      Protected    Normal.Vector3, returnMesh.i
      Color.l = $FFFFFF
      
      returnMesh = MP_CreateMesh()
      
      If numSegBase < 1
        numSegBase = 1
      EndIf
     
      If numSegHeight < 1
        numSegHeight = 1
      EndIf
     
      deltaAngle.f = #PI*2 / numSegBase
      deltaHeight.f = height / numSegHeight
      height2.f = height / 2.0
      offset = 0
     
      For i = 0 To numSegHeight
        For j = 0 To numSegBase
         
          x0.f = outerRadius * Cos(j*deltaAngle)
          z0.f = outerRadius * Sin(j*deltaAngle)
         
          Normal\x = x0
          Normal\y = 0
          Normal\z = z0
          Normalize(@Normal)
          
          MP_AddVertex(returnMesh,x0, i*deltaHeight-height2, z0 , Color , j / numSegBase, i / numSegHeight, Normal\x, Normal\y, Normal\z)
          
          If  i <> numSegHeight
            MP_AddTriangle(returnMesh,offset + numSegBase + 1,offset,offset + numSegBase)
            MP_AddTriangle(returnMesh,offset + numSegBase + 1,offset + 1,offset)
          EndIf
          offset + 1
        Next
      Next 
      
      For i = 0 To numSegHeight
        For j = 0 To numSegBase
         
          x0.f = innerRadius * Cos(j*deltaAngle)
          z0.f = innerRadius * Sin(j*deltaAngle)
         
          Normal\x = x0
          Normal\y = 0
          Normal\z = z0
          Normalize(@Normal)
          
          MP_AddVertex(returnMesh,x0, i*deltaHeight-height2, z0 , Color , j / numSegBase, i / numSegHeight, Normal\x, Normal\y, Normal\z)
          
          If  i <> numSegHeight
            MP_AddTriangle(returnMesh,offset + numSegBase + 1,offset + numSegBase,offset)
            MP_AddTriangle(returnMesh,offset + numSegBase + 1,offset,offset + 1)
          EndIf
          offset + 1
        Next
      Next 
      
      For j = 0 To numSegBase
       
        x0.f = innerRadius * Cos(j*deltaAngle)
        z0.f = innerRadius * Sin(j*deltaAngle)
        
        MP_AddVertex(returnMesh,x0, -height2, z0 , Color , j / numSegBase, 1, 0, -1, 0)
       
        x0 = outerRadius * Cos(j*deltaAngle)
        z0 = outerRadius * Sin(j*deltaAngle)
        
        MP_AddVertex(returnMesh,x0, -height2, z0 , Color , j / numSegBase, 0, 0, -1, 0)
       
        If j <> numSegBase
          MP_AddTriangle(returnMesh,offset,offset + 1,offset + 3)
          MP_AddTriangle(returnMesh,offset + 2,offset ,offset + 3)
        EndIf
        offset + 2
      Next    
      
      For j = 0 To numSegBase
        x0.f = innerRadius * Cos(j*deltaAngle)
        z0.f = innerRadius * Sin(j*deltaAngle)
        
        MP_AddVertex(returnMesh,x0, height2, z0 , Color , j / numSegBase, 0, 0, 1, 0)
        
        x0 = outerRadius * Cos(j*deltaAngle)
        z0 = outerRadius * Sin(j*deltaAngle)
        
        MP_AddVertex(returnMesh,x0, height2, z0 , Color , j / numSegBase, 1, 0, 1, 0)
      
        If j <> numSegBase
          MP_AddTriangle(returnMesh,offset + 1,offset,offset + 3)
          MP_AddTriangle(returnMesh,offset, offset +2,offset + 3)
        EndIf
        offset + 2
      Next
      
       ProcedureReturn returnMesh
 EndProcedure   
           
 Procedure MP_CreateOpenCylinder(Radius.f, height.f, numSegBase=16, numSegHeight=1)
     
      Protected    Normal.Vector3, returnMesh.i
      Color.l = $FFFFFF
      
      returnMesh = MP_CreateMesh()
      
      If numSegBase < 1
        numSegBase = 1
      EndIf
     
      If numSegHeight < 1
        numSegHeight = 1
      EndIf
     
      deltaAngle.f = #PI*2 / numSegBase
      deltaHeight.f = height / numSegHeight
      height2.f = height / 2.0
      offset = 0
     
      For i = 0 To numSegHeight
        For j = 0 To numSegBase
         
          x0.f = Radius * Cos(j*deltaAngle)
          z0.f = Radius * Sin(j*deltaAngle)
         
          Normal\x = x0
          Normal\y = 0
          Normal\z = z0
          Normalize(@Normal)
          
          MP_AddVertex(returnMesh,x0, i*deltaHeight-height2, z0 , Color , j / numSegBase, i / numSegHeight, Normal\x, Normal\y, Normal\z)
          
          If  i <> numSegHeight
            MP_AddTriangle(returnMesh,offset + numSegBase + 1,offset,offset + numSegBase)
            MP_AddTriangle(returnMesh,offset + numSegBase + 1,offset + 1,offset)
          EndIf
          offset + 1
        Next
      Next 
      
   ProcedureReturn returnMesh
 EndProcedure 

MP_Graphics3D (640,480,0,3) ; Create a Window with 3D function #Window = 0
SetWindowTitle(0, "3D with two cylinders")

camera=MP_CreateCamera() ; camera on

light=MP_CreateLight(1) ; yes light

Mesh1=MP_CreateOpenCylinder(1.5, 3, 16, 1) ; my Cylinder normal
Mesh2=CreateTube(1.5, 1, 3, 16, 1)
     

MP_PositionEntity (Mesh1,-3,0,8) ; Position mesh1
MP_PositionEntity (Mesh2,3,0,8) ; Position mesh2

While Not MP_KeyDown(#PB_Key_Escape) And Not WindowEvent() = #PB_Event_CloseWindow; Esc abfrage oder Windows Schliessen
 
    MP_TurnEntity (Mesh1,1,0.5,0.5) ; go to moving
    MP_TurnEntity (Mesh2,1,0.5,0.5) ; mee too
   
    MP_RenderWorld() ; render the world
    MP_Flip () ; show me the world
   
Wend
Working on - MP3D Library - PB 5.73 version ready for download
Post Reply