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 »

the Michael two procedures seems to work well, since we can move a ball inside these hollow tubes with physics type 1 ie static, which accepts a sphere to go inside.
i thought of Psychophanta approach to delete triangles. but it seems not real hollow, the ball does not pass through with MP_EntityPhysicBody(shape, 1, 1) after removing the cylinder 2 sides triangles

Michael code tubes with physics:
(but why we can't see the ball pass through a supposed transparent tube with MP_CreateOpenCylinder.)

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
MP_PositionEntity(camera,4,6,-10)
MP_EntityLookAt(camera, 0, 3, 0)

light=MP_CreateLight(1) ; yes light
MP_PositionEntity (light,-6,10,-3)
MP_LightSetColor(light,RGB(255,255,255))
MP_EntityLookAt(light,0,0,0)


Mesh1=MP_CreateOpenCylinder(1.5, 6, 16, 1) ; my Cylinder normal
Mesh2=CreateTube(1.5, 1, 6, 16, 1)
MP_RotateMesh(Mesh2, 60,33,0)
     

MP_PositionEntity (Mesh1,-3,0,8) ; Position mesh1
MP_RotateMesh(Mesh1, 60,0,0)
MP_PositionEntity (Mesh2,3,0,8)  ; Position mesh2
MP_PhysicInit()
MP_EntityPhysicBody(Mesh1, 1, 1)
MP_EntityPhysicBody(Mesh2, 1, 1)

tex2 =  MP_LoadTexture(#PB_Compiler_Home + "Examples\3D\Data\Textures\MRAMOR6X6.jpg")
MP_EntitySetTexture(Mesh1, tex2)
MP_MeshSetAlpha (Mesh1,3)
MP_MaterialEmissiveColor (tex2,0,50,50,50)
MP_MaterialAmbientColor(tex2, 0, 255 ,200, 11)
MP_MeshSetBlendColor(Mesh1, MP_ARGB(100,255,255,255))



sphere = MP_CreateSphere(8)
 MP_ScaleMesh(sphere, 0.3, 0.3, 0.3)
 MP_PositionEntity(sphere,-3,3,10)
 MP_EntityPhysicBody(sphere, 3, 1)
 MP_EntitySetGravity(sphere, 0 , -1 ,0)
 tex3 =  MP_LoadTexture(#PB_Compiler_Home + "Examples\3D\Data\Textures\Geebee2.bmp")
 MP_EntitySetTexture(sphere, tex3)
 
 sphere2 = MP_CreateSphere(8)
 MP_ScaleMesh(sphere2, 0.3, 0.3, 0.3)
 MP_PositionEntity(sphere2, 4.5,4,10.0)
 MP_EntityPhysicBody(sphere2, 3, 1)
 MP_EntitySetGravity(sphere2, 0 , -1 ,0)
 tex3 =  MP_LoadTexture(#PB_Compiler_Home + "Examples\3D\Data\Textures\Geebee2.bmp")
 MP_MaterialEmissiveColor (tex3,0,50,50,50)
MP_MaterialAmbientColor(tex3, 0, 255 ,200, 11)
MP_MeshSetBlendColor(Mesh1, MP_ARGB(100,255,255,255))

 MP_MeshSetAlpha (Mesh2,1)
 MP_EntitySetTexture(Mesh2, tex3)



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_PhysicUpdate()
    MP_RenderWorld() ; render the world
    MP_Flip () ; show me the world
   
Wend
Last edited by applePi on Mon Feb 01, 2016 12:03 pm, edited 2 times in total.
User avatar
Psychophanta
Addict
Addict
Posts: 4969
Joined: Wed Jun 11, 2003 9:33 pm
Location: Lípetsk, Russian Federation
Contact:

Re: MP3D Engine Alpha 32

Post by Psychophanta »

mpz wrote:... found a problem in MP_AddVertex and MP_AddTriangle (it crashed with my translated code). I have found the problem...
Please listen this request:
In the same way we use 3 coordinates to MP_AddTriangle, then we should be able to rescue this 3 parameters from any triangle, so the request is a parameter #PB_Mesh_TriangleList for MP_GetMeshData() and get the complete triangle list with its structures:
Structure Triangle
*D1.D3DXVECTOR3
*D2.D3DXVECTOR3
*D3.D3DXVECTOR3
EndStructure


BTW, as a workaround we can also use this to make a tube: hehe! ;)

Code: Select all

MP_Graphics3D(640,480,0,3)
SetWindowTitle(0,"tubo")
cam=MP_CreateCamera():MP_PositionEntity(cam,0,0,-3)
light=MP_CreateLight(1)
Mesh=MP_Create3DText("Rondalo","O",4):MP_TranslateMesh(Mesh,-1.33333,-1.33333,0.2)
MP_ResizeMesh(Mesh,1,1,1)
While MP_KeyDown(#PB_Key_Escape)=0 And WindowEvent()<>#PB_Event_CloseWindow
  MP_TurnEntity (Mesh,1,0.5,0.5)
  MP_RenderWorld()
  MP_Flip()
Wend
http://www.zeitgeistmovie.com

While world=business:world+mafia:Wend
Will never leave this forum until the absolute bugfree PB :mrgreen:
applePi
Addict
Addict
Posts: 1404
Joined: Sun Jun 25, 2006 7:28 pm

Re: MP3D Engine Alpha 32

Post by applePi »

making a big Wheel (UFO) from several cylinders
no explicit cos, sin math here to fabricate a big wheel, it is better to use hollow tubes (MP_CreateOpenCylinder) instead of cylinders, but i want the code very short (until the tubes functions implemented internally in mp3d )
Edit: code edited to be compatible with latest Library

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, "press '1' or '2' to change Camera view position, .... 'W' toggle wire/solid frame")

light= MP_CreateLight(2) 
MP_PositionEntity(light, 0, 10, 0)
MP_LightSetColor(light,RGB(255,255,255))
MP_AmbientSetLight (RGB(150,150,200))
MP_EntityLookAt(light,0,0,0)

cam = MP_CreateCamera()

MP_PositionEntity(cam, 0, 15, -20)
MP_EntityLookAt(cam, 0, 0, 0)

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

tex3 =  MP_LoadTexture(#PB_Compiler_Home + "Examples\3D\Data\Textures\MRAMOR6X6.jpg")
  
sphere = MP_CreateSphere(8)
 MP_ScaleMesh(sphere, 0.3, 0.3, 0.3)
 MP_PositionEntity(sphere,-6,0,0)

Dim cyl(19)
cyl(0)=MP_CreateCylinder(2,2)
MP_RotateMesh(cyl(0), 90,0,0)
MP_PositionEntity(cyl(0),0,5,0)
c=0 

    For i=1 To 360
    ; the green sphere is a guidance for positioning and orientation of cylinders
    MP_MoveEntity(sphere, 0, 0, -0.1)
    MP_TurnEntity(sphere, 0, -1, 0 )
   
   If Mod(i,20)=0
    c+1
     
    cyl(c)=MP_CreateCylinder(2,2)
    MP_ScaleMesh(cyl(c), 0.6, 0.6, 1.0)
    MP_RotateMesh(cyl(c), MP_EntityGetPitch(sphere) ,MP_EntityGetYaw(sphere) ,MP_EntityGetRoll(sphere)+90)
    MP_TranslateMesh(cyl(c), MP_EntityGetX(sphere), MP_EntityGetY(sphere)-4, MP_EntityGetZ(sphere))
    MP_AddMesh(cyl(c), cyl(0))
    MP_FreeEntity(cyl(c))
    
  EndIf 
 Next
 
 MP_EntitySetTexture(sphere, tex0)
 
 ;;oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo
Global w = 1
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, 20, -0.1)
    MP_EntityLookAt(cam, 0, 0, 0)
ElseIf MP_KeyHit(#PB_Key_2) 
  MP_PositionEntity(cam, 0, 7, -20)
  MP_EntityLookAt(cam, 0, 0, 0)
ElseIf MP_KeyHit(#PB_Key_W)
  If w: mp_wireframe(w) : w * -1: EndIf
EndIf

MP_MoveEntity(sphere, 0, 0, -0.1) 
MP_TurnEntity(sphere, 0, -1, 0 ) ; rotate the sphere

MP_TurnEntity(cyl(0), 0, -1, 0 ) ; rotate the wheel
      
 MP_RenderWorld() ; Erstelle die Welt
 MP_Flip () ; Stelle Sie dar
     
Wend

End
Last edited by applePi on Mon Feb 08, 2016 7:49 pm, edited 1 time in total.
User avatar
Psychophanta
Addict
Addict
Posts: 4969
Joined: Wed Jun 11, 2003 9:33 pm
Location: Lípetsk, Russian Federation
Contact:

Re: MP3D Engine Alpha 32

Post by Psychophanta »

@applePi, why not to create a torus for such a task instead of several cylinders?
http://www.zeitgeistmovie.com

While world=business:world+mafia:Wend
Will never leave this forum until the absolute bugfree PB :mrgreen:
applePi
Addict
Addict
Posts: 1404
Joined: Sun Jun 25, 2006 7:28 pm

Re: MP3D Engine Alpha 32

Post by applePi »

Psychophanta, of course it is better to do it with torus but i was comparing glTranslatef and glRotatef_ with MP_MoveEntity and MP_TurnEntity (or MP_RotateEntity ).
the two groups of functions is accumulating values , but glTranslatef is accumulating in general and for all cylinders unless we zeroed it with glLoadIdentity. while MP_MoveEntity (it seems) accumulating values to just the current object. the opengl tree posted before seems hard to implement because this feature + its recursive nature
but this twig simulation in Opengl is more possible to imitate in ogre or mp3d since there is no recursion in it. but even it is small size but it is complex
the code algorithm is not mine, and translated to PB using OpenGLGadget
uncomment line 146 gluSphere_(qobj, radius, 8 , 8 ) to fill the gaps between cylinders

Code: Select all

Procedure.f RandF(Min.f, Max.f, Resolution.i = 10000)
  ProcedureReturn (Min + (Max - Min) * Random(Resolution) / Resolution)
EndProcedure

Declare MakeTwig( Iterations.l, Radius.f, RadiusMlt.f, Leng.f, LengMlt.f, Angle.f)
Global cylinderList = 1

Global rota.f = 0
Global dist.f = 4

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

Define event, quit

InitKeyboard()

OpenWindow(0, 0, 0, 800, 600, "OpenGL demo .. 3D Tree Twig")
SetWindowColor(0, RGB(200,220,200))
OpenGLGadget(0, 20, 10, WindowWidth(0)-40 , WindowHeight(0)-20, #PB_OpenGL_Keyboard )

Global Dim LightPos.f(4) ;Light Position
 LightPos(0)= 0.0 : LightPos(1)= 5.0 : LightPos(2)=-4.0 : LightPos(3)= 1.0
Global Dim LightAmb.f(4) ;Ambient Light Values
 LightAmb(0)= 0.2 : LightAmb(1)= 0.2 : LightAmb(2)= 0.2 : LightAmb(3)= 1.0
Global Dim LightDif.f(4) ;Diffuse Light Values
 LightDif(0)= 0.6 : LightDif(1)= 0.6 : LightDif(2)= 0.6 : LightDif(3)= 1.0
Global Dim LightSpc.f(4) ;Specular Light Values
LightSpc(0)=-0.2 : LightSpc(1)=-0.2 : LightSpc(2)=-0.2 : LightSpc(3)= 1.0


Global Dim MatAmb.f(4) ;Material - Ambient Values
 MatAmb(0)= 0.4 : MatAmb(1)= 0.4 : MatAmb(2)= 0.4 : MatAmb(3)= 1.0
Global Dim MatDif.f(4) ;Material - Diffuse Values
 MatDif(0)= 1.2 : MatDif(1)= 0.6 : MatDif(2)= 0.0 : MatDif(3)= 1.0
Global Dim MatSpc.f(4) ;Material - Specular Values
 MatSpc(0)= 0.0 : MatSpc(1)= 0.0 : MatSpc(2)= 0.0 : MatSpc(3)= 1.0
Global Dim MatShn.f(1) ;Material - Shininess
MatShn(0)= 0.0

glClearColor_ (0.0, 0.0, 0.0, 0.0);
glShadeModel_ (#GL_SMOOTH)

glEnable_(#GL_LIGHTING);
glEnable_(#GL_LIGHT0);
glEnable_(#GL_DEPTH_TEST);

glLightfv_(#GL_LIGHT1,#GL_POSITION,LightPos()) ;Set Light1 Position
glLightfv_(#GL_LIGHT1,#GL_AMBIENT,LightAmb()) ;Set Light1 Ambience
glLightfv_(#GL_LIGHT1,#GL_DIFFUSE,LightDif()) ;Set Light1 Diffuse
glLightfv_(#GL_LIGHT1,#GL_SPECULAR,LightSpc()) ;Set Light1 Specular
glEnable_(#GL_LIGHT1) ;Enable Light1
glEnable_(#GL_LIGHTING) ;Enable Lighting
 
glMaterialfv_(#GL_FRONT,#GL_AMBIENT,MatAmb()) ;Set Material Ambience
glMaterialfv_(#GL_FRONT,#GL_DIFFUSE,MatDif()) ;Set Material Diffuse
glMaterialfv_(#GL_FRONT,#GL_SPECULAR,MatSpc()) ;Set Material Specular
glMaterialfv_(#GL_FRONT,#GL_SHININESS,MatShn());Set Material Shininess

;a1=Random(8,5): a2.f = Randf(0.4,0.6): a3.f=Randf(0.9,0.95): a4.f=Randf(0.9,0.95) : a5.f=Randf(20,40)
;MakeTwig(Random(8,5), Randf(0.4,0.6), Randf(0.9,0.95), 1, Randf(0.9,0.95), Randf(20,40))     
;a1=1
;MakeTwig(a1, a2, a3, 1, a4, a5)
;Debug a1:Debug a2:Debug a3:Debug a4:Debug a5
;**********************************************
MakeTwig(1, 0.5, 0.92, 1, 0.93, 25)
 
  Global i.l, j.l
  Global Distance.f = 25
  
  Global RotY.f , RotX.f, gRotY.f, gRotX.f
  
  Global twig.s
    
  SetActiveGadget(0) ; make the openGLgadget active
  
  Repeat
    Event = WindowEvent()
  
  
  If Event = #PB_Event_Gadget And EventGadget() = 0 
   If EventType() = #PB_EventType_KeyDown
      
            key = GetGadgetAttribute(0,#PB_OpenGL_Key )
            
            If key = #PB_Shortcut_Up
              
               dist.f + 3
               ElseIf key = #PB_Shortcut_Down ; Down arrow key  
               dist.f - 3
               
              ElseIf key = #PB_Shortcut_Escape ;  Esc key to exit

             quit = 1
            EndIf  
     EndIf
   EndIf
  
  
  glEnable_(#GL_DEPTH_TEST)
  glEnable_(#GL_BLEND);
  ;glDisable_(#GL_DEPTH_TEST)
  glViewport_(0, 0, WindowWidth(0), WindowHeight(0))
  glMatrixMode_(#GL_PROJECTION)
  glLoadIdentity_()
  gluPerspective_(60.0, Abs(WindowWidth(0) / WindowHeight(0)), 0.1, 2000.0)
  glMatrixMode_(#GL_MODELVIEW)
  glLoadIdentity_()
  glClear_(#GL_COLOR_BUFFER_BIT | #GL_DEPTH_BUFFER_BIT)
   glLoadIdentity_ ()
   ;viewing transformation  
   glTranslatef_(0.0, -2.0, dist); 
   gluLookAt_(0,0,-17, 0,0.0,0, 0,1,0); camera position :(eye, object, vector)
    
   rota+1
   glRotatef_(rota, 0.0, 1.0, 0.0)
   glCallList_(cylinderList)
  
SetGadgetAttribute(0, #PB_OpenGL_FlipBuffers, #True)  
Until Event = #PB_Event_CloseWindow Or quit = 1
 
  Procedure MakeTwig( Iterations.l, Radius.f, RadiusMlt.f, Leng.f, LengMlt.f, Angle.f)
  ;MakeTwig(1, 0.5, 0.92, 1, 0.93, 25)
    
    char.s
   
    cylinderList = glGenLists_(1) 
    glNewList_(cylinderList, #GL_COMPILE_AND_EXECUTE)
; the genes of the twig
twig = "x+abz+y+aby+aby-abx-abx-abz-abz-abz-aby-abx-y-abz+abz-abx-abx-abx-x+aby+abx+abx-aby+aby-abz-abz+x-aby-aby-aby-abx+abx-abz+z-abx-abz+abx+aby+abx-abx+aby+aby-x+abz-aby-abz+abz-abz+abz-aby-aby+x+aby-abx+abz-abz-aby+abz+abz+abz+abx+z-abz-x-abz+abz-abz+aby-abz+abz-aby-aby+abz-abx+z+aby-abx-aby+abz+abz-abx+x+abz+abz+abx+abz+abx+aby+abx+z+abz-abx-abx-y+aby+abx-abz-abx-abx+aby-abx-aby-abx+abx-abx+abz+aby+abz+abz+y+abx-abz-abx-aby-abz+abx+aby+aby-aby+abx+abx+aby-abx+abz-aby+aby+abx-abx-z+abz+x+abx+abx+abz+abx+abz+abx-abz-abx+abz+abx-z-aby+aby+aby-abz+aby-aby+abx-abz-aby+abz-aby+abz-abz-abx-" 
      glPushMatrix_()
        For i = 1 To Len(twig)
          char = Mid(twig, i, 1)
          
          Select char
            Case "a"
              total+1
              glPushMatrix_()
                glRotatef_(-90,1,0,0)
                gluCylinder_(qobj, radius , radius*radiusmlt, leng, 8, 8) ; 8,8: slices, stacks
              glPopMatrix_()
              
              ;gluSphere_(qobj, radius, 8, 8);
                          
            Case "b" 
              ;glLoadIdentity_()
              glTranslatef_( 0,leng+0.0,0)
              radius * radiusmlt
              leng * lengmlt
              
            Case "+"            
              If axis = 1  
                glRotatef_(angle, 1, 0, 0)
              ElseIf axis = 2  
                glRotatef_( angle, 0, 1, 0)            
              ElseIf axis = 3                
                glRotatef_(angle, 0, 0, 1)                          
              EndIf  
                
            Case "-"            
              If axis = 1
                glRotatef_( -angle, 1, 0, 0)
              ElseIf axis = 2  
                glRotatef_(-angle, 0, 1, 0)
              ElseIf axis = 3                
                glRotatef_(-angle, 0, 0, 1)                          
              EndIf  
              
            Case "x"
              axis = 1           
              
            Case "y"
              axis = 2            
              
            Case "z"
              axis = 3           
                   
              
          EndSelect  

        Next 
        ;Debug total
      glPopMatrix_()
            
    glEndList_()
  
  EndProcedure
  
mpz
Enthusiast
Enthusiast
Posts: 494
Joined: Sat Oct 11, 2008 9:07 pm
Location: Germany, Berlin > member German forum

Re: MP3D Engine Alpha 32

Post by mpz »

Hi to all,

i have changed the MP_Createcylinder(). I looked in the Purebasic CreateCylinder() rules and have made it in the same kind

MP_Createcylinder(radius.f, height.f [, radius2.f numSegBase, numSegHeight, close])

You have now 2 radius functions and open/close function too

@applePi, you can make a long cylinder conical and move the vertex to create your "tree bough".

I think about to create a funktion to twist and move vertex with mathematical funktions. With these functions you can make spirals and other crazy things from basic meshs. I have done it before with a twist shader and it looks great...

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

Greetings Michael

Code: Select all

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

;MP_Wireframe(1) 

camera=MP_CreateCamera() ; camera on

light=MP_CreateLight(1) ; yes light

Mesh1=MP_CreateCylinder(1,4) ; my Cylinder normal
 
Mesh2=MP_CreateCylinder(0.3,4,1.5,16,12,1) ; my Cylinder conical
 
Mesh3=MP_CreateCylinder(0.3,4,1.5,16,12,0) ; my Cylinder conical and open
 

MP_PositionEntity (Mesh1,-4,0,12) ; Position mesh1
MP_PositionEntity (Mesh2,0,0,12) ; Position mesh2
MP_PositionEntity (Mesh3,4,0,12) ; Position mesh3

MP_TurnEntity (Mesh1,90,0,0) ; turn me to look better
MP_TurnEntity (Mesh2,90,0,0) ; mee too
MP_TurnEntity (Mesh3,90,0,0) ; mee too

While Not MP_KeyDown(#PB_Key_Escape) And Not WindowEvent() = #PB_Event_CloseWindow; Esc abfrage oder Windows Schliessen
  
    MP_TurnEntity (Mesh1,0.5,1,0) ; go to moving
    MP_TurnEntity (Mesh2,0.5,1,0) ; mee too
    MP_TurnEntity (Mesh3,0.5,1,0) ; 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
User avatar
Psychophanta
Addict
Addict
Posts: 4969
Joined: Wed Jun 11, 2003 9:33 pm
Location: Lípetsk, Russian Federation
Contact:

Re: MP3D Engine Alpha 32

Post by Psychophanta »

Thanks for it, Michael.

I needed a half of a torus and wrote a versatile function for a torus arc lenght:

Code: Select all

Define.f
MP_Graphics3D(640,480,0,1)
SetWindowTitle(0,"Torus arc Mesh")
maincam.i=MP_CreateCamera():pivotcam.i=MP_CreateMesh():MP_EntitySetParent(maincam,pivotcam,0):MP_PositionEntity(maincam,0,0,-5)
light.i=MP_CreateLight(2)
MP_WireFrame(1)
Structure D3DXVECTOR3
  x.f:y.f:z.f
EndStructure 
Structure Vector3D Extends D3DXVECTOR3
  m.f;<-length(modulo)
EndStructure
Macro Wrap(number,margin1,margin2)
  (margin1#+(number#)%((margin2#)-(margin1#)))
EndMacro
Macro ProductoEscalar(a,b)
  (a#\x*b#\x+a#\y*b#\y+a#\z*b#\z)
EndMacro
Macro getmodulo(v)
  (Sqr#ProductoEscalar(v#,v#))
EndMacro
Procedure Rotate_3DVector_by_Angle_adding(*fi.Vector3D,*R0.Vector3D)
  ;Esta funcion halla un vector resultado de una rotacion en el espacio de otro vector inicial.
  ;Esta funcion admite entonces, como parametros de entrada, 2 vectores:
  ; - 'Vector radio' que se desea rotar. Este vector tiene direccion no colineal con el eje de rotación.
  ; - 'Vector angulo' ('velocidad angular' * 'tiempo'), es el angulo en el que se rota el 'Vector radio' dado.
  ;     Su modulo indica el numero de radianes a rotar, su direccion indica el angulo en el espacio en el que se rota (eje de rotación)
  ;     su sentido indica el sentido de la rotacion
  ;NOTA: la funcion devuelve el vector velocidad rectilinea (3er parametro) y el nuevo vector radio (4º parametro)
  ;       pero ambos parametros se pueden omitir haciendo que la velocidad rectilinea no se devuelva y que el nuevo radio se devuelva en el 2º parametro
  Protected Rt.Vector3D,u.Vector3D,P0.Vector3D
  *fi\m=ProductoEscalar(*fi,*fi)
  If *fi\m
    u\m=ProductoEscalar(*R0,*fi)/*fi\m
    *fi\m=Sqr(*fi\m)
    ;Proyeccion de *R0 sobre *fi:
    Rt\x=u\m**fi\x
    Rt\y=u\m**fi\y
    Rt\z=u\m**fi\z
    ;Calcular P0-> (proyeccion ortogonal de *R0 sobre *fi):
    P0\x=*R0\x-Rt\x
    P0\y=*R0\y-Rt\y
    P0\z=*R0\z-Rt\z
    P0\m=getmodulo(P0)
    If P0\m=0.0:ProcedureReturn:EndIf
    ;Calcular el producto vectorial: u-> = *fi-> X P0->
    u\x=*fi\y*P0\z-*fi\z*P0\y
    u\y=*fi\z*P0\x-*fi\x*P0\z
    u\z=*fi\x*P0\y-*fi\y*P0\x
    ;ahora obtener *R0-> = (Proyeccion de *R0 sobre *fi)-> + (cos(|*fi->|)·P0-> + |P0->|/|u->|·sin(|*fi->|)·u->)->:
    u\m=getmodulo(u)
    *R0\x=Rt\x
    *R0\y=Rt\y
    *R0\z=Rt\z
    !mov edi,dword[p.p_fi]
    !fld dword[edi+12]; <- get *fi\m
    !fsincos
    !fstp dword[p.v_Rt]; <- Rt\x=Cos(*fi\m)
    !fstp dword[p.v_Rt+4]; <- Rt\y=Sin(*fi\m)
    ; o bien si no se quiere usar ensamblador sustituirlo por
    ; Rt\x=Cos(*fi\m):Rt\y=Sin(*fi\m)
    *R0\x+Rt\x*P0\x+P0\m/u\m*Rt\y*u\x
    *R0\y+Rt\x*P0\y+P0\m/u\m*Rt\y*u\y
    *R0\z+Rt\x*P0\z+P0\m/u\m*Rt\y*u\z
    *R0\m=P0\m
  EndIf
EndProcedure
Procedure.i CreateTorusArc(l.l,lt.l,r0.f,r1.f,rt.f,at.f,t.f=0.0)
  If l<2 Or lt<2 Or r0<0 Or r1<0 Or rt<0.0001:ProcedureReturn 0:EndIf
  Protected Mesh.i=MP_CreateMesh(),vert.Vector3D,ang.Vector3D,a.l,b.l,p.f,torsion.f,v0.l,v1.l
  ;l = numero de lados en la seccion (number of sides in cut area)
  ;lt = lados toro (number of sides of torus)
  ;r0 = radio grosor inicial (radius of cut area at initial extreme)
  ;r1 = radio grosor final (radius of cut area at end extreme)
  ;rt = radio del toro (radius of torus)
  ;at = longitud del arco del toro (arc lenght of the torus)
  ;t = torsion (torsion)
  For b=0 To lt
    For a=0 To l-1
      p=r0+(r1-r0)*b/lt
      vert\x=rt+p*Cos(2*#PI*a/l+torsion) +(r1-r0)*b/lt/2
      vert\y=p*Sin(2*#PI*a/l+torsion)
      vert\z=0
      If b<>0
        ang\x=0:ang\y=-at*b/lt:ang\z=0
        Rotate_3DVector_by_Angle_adding(@ang,@vert)
      EndIf
      MP_AddVertex(Mesh.i,vert\x,vert\y,vert\z,0,Int(a/l)/(lt+1),Mod(a,l)/l)
      ;sp.i=MP_CreateSphere(8):MP_ResizeMesh(sp,0.1,0.1,0.1):MP_PositionEntity(sp,vert\x,vert\y,vert\z)
    Next
    torsion+t
  Next
  For b=0 To lt-1
    For a=0 To l-1
      v0=Wrap(b*l+a,b*l,b*l+l):v1=Wrap(b*l+a+l+1,b*l+l,b*l+2*l); <- uso estas variables para no recalcularlas (para ganar tiempo)
      MP_AddTriangle(Mesh.i,v0,Wrap(b*l+a+l,b*l+l,b*l+2*l),v1)
      MP_AddTriangle(Mesh.i,v0,Wrap(b*l+a+1,b*l,b*l+l),v1)
    Next
  Next
  MP_EntitySetNormals(Mesh.i)
  ProcedureReturn Mesh.i
EndProcedure
; Tor.i=CreateTorusArc(25,3,0.4,0,2,#PI,0)
; Tor.i=CreateTorusArc(3,30,1,0,2,#PI/3,0)
; Tor.i=CreateTorusArc(16,30,0.4,0.4,2,#PI,0)
; Tor.i=CreateTorusArc(16,30,1,0,2,2.2*#PI,0)
Tor.i=CreateTorusArc(4,10,1,0.5,2,#PI/2,0.1)
Texture.i=MP_CreateTextureColor(8,8,$888899ee):MP_EntitySetTexture(Tor,Texture)
While MP_KeyDown(#PB_Key_Escape)=0 And WindowEvent()<>#PB_Event_CloseWindow
  mdx=MP_MouseDeltaX()/200:mdy=MP_MouseDeltaY()/200:mdw=MP_MouseDeltaWheel()/400
  If MP_MouseButtonDown(1)
    MP_TurnEntity(pivotcam,mdy*60,mdx*60,0,0)
    If mdw
      MP_EntitySetZ(maincam,MP_EntityGetZ(maincam)+mdw); <- MP_MoveEntity(maincam,0,0,mdw)
    EndIf
    *rot=MP_EntityGetMatrix(pivotcam)
  EndIf
  MP_RenderWorld()
  MP_Flip()
Wend
http://www.zeitgeistmovie.com

While world=business:world+mafia:Wend
Will never leave this forum until the absolute bugfree PB :mrgreen:
applePi
Addict
Addict
Posts: 1404
Joined: Sun Jun 25, 2006 7:28 pm

Re: MP3D Engine Alpha 32

Post by applePi »

you are the best Michael, yes this is what the cylinder should be, especially the cylinder conical with open sides like a funnel, thank you very much.
i think about to create a funktion to twist and move vertex with mathematical funktions. With these functions you can make spirals and other crazy things from basic meshs
this will be great, everything crazy and bizarre is great, such as mimicking clouds, twisters, tornadoes, vapor, and i wish to mimic body decomposition like that in some movies
best wishes
User avatar
Psychophanta
Addict
Addict
Posts: 4969
Joined: Wed Jun 11, 2003 9:33 pm
Location: Lípetsk, Russian Federation
Contact:

Re: MP3D Engine Alpha 32

Post by Psychophanta »

An old question:
Why the meshes have more vertex count than they appear to have?:
in this tip there are 12 vertex, but the displayed mesh has only 9:

Code: Select all

MP_Graphics3D(640,480,0,3)
SetWindowTitle(0,"3D with new cylinder")
MP_Wireframe(1)
camera=MP_CreateCamera():MP_PositionEntity(camera,0,0,-12)
light=MP_CreateLight(1)
;   MP_Createcylinder(radius.f,height.f[,radius2.f,numSegBase,numSegHeight,close])
newcyl=MP_CreateCylinder(3,4,1.5,3,2,0)
MP_TurnEntity(newcyl,90,0,0)
While MP_KeyDown(#PB_Key_Escape)=0 And WindowEvent()<>#PB_Event_CloseWindow
  MP_TurnEntity(newcyl,0.5,1,0)
  MP_DrawText(1,1,Str(MP_CountVertices(newcyl))+", "+Str(MP_CountTriangles(newcyl)))
  MP_RenderWorld()
  MP_Flip()
Wend
http://www.zeitgeistmovie.com

While world=business:world+mafia:Wend
Will never leave this forum until the absolute bugfree PB :mrgreen:
applePi
Addict
Addict
Posts: 1404
Joined: Sun Jun 25, 2006 7:28 pm

Re: MP3D Engine Alpha 32

Post by applePi »

@Psychophanta, look at the following edited version of your demo, first press space to rotate the cylinder mesh to a proper place, then press 'Z' to make a small sphere jump to vertex 0, then vertex 1, ...etc . you will see vertex 3 is at the same place at vertex 0 this is to connect it to other vertex.
the last index is 11 (0 to 11)
when we reach n=13 we get error so let the debugger active
i will try to look later how the triangles connected
i have used the example attached to MP_GetMeshData() in the help file in this demo

Code: Select all

Structure MyVertex 
      x.f : y.f : z.f      ; vertices coordinates 
      nx.f : ny.f : nz.f ; normal coordinates
      Color.l                  ; color 
      u.f : v.f               ; texture coordinates 
      ;u1.f : v1.f               ; texture coordinates 2 
      ;u2.f : v2.f               ; texture coordinates 2 
EndStructure 
    
MP_Graphics3D(640,480,0,3)
SetWindowTitle(0,"3D with new cylinder")
MP_Wireframe(1)
camera=MP_CreateCamera():MP_PositionEntity(camera,0,7,-12)
MP_EntityLookAt(camera, 0,0,0)
MP_CameraViewPort(camera, 0, 0, 600, 600 , RGB(100,100,0))

;MP_CameraSetPerspective(camera, 45)
light=MP_CreateLight(1) 
MP_LightSetColor (light, RGB(0, 255, 0))

MP_PositionEntity(light,0,10,-2)
MP_EntityLookAt(light, 0,0,0)
;MP_Createcylinder(radius.f,height.f[,radius2.f,numSegBase,numSegHeight,close])
newcyl=MP_CreateCylinder(3,4,1.5,3,2,0)
MP_PositionEntity(newcyl,0,0,0)

MP_TurnEntity(newcyl,0,0,0)
sphere = MP_CreateSphere(16): MP_ScaleMesh(sphere, 0.1, 0.1, 0.1)
vertexcount = MP_CountVertices(newcyl)
vertexlenght = MP_GetMeshInfo (newcyl, 64)
Dim Vert.MyVertex (vertexcount)
MP_GetMeshData(newcyl, #PB_Mesh_Vertex,@Vert(),vertexlenght * vertexcount)

n=-1
While MP_KeyDown(#PB_Key_Escape)=0 And WindowEvent()<>#PB_Event_CloseWindow
  If MP_Keydown(#PB_Key_Space)
    ;MP_TurnEntity(newcyl,0.0,1,0)
    MP_RotateMesh(newcyl, 0.0,1,0)
    MP_GetMeshData(newcyl, #PB_Mesh_Vertex,@Vert(),vertexlenght * vertexcount)
  EndIf
  
  If MP_KeyHit(#PB_Key_Z)
    n+1
    MP_PositionEntity(sphere,vert(n)\x,vert(n)\y,vert(n)\z)
        
  EndIf
    
  
  MP_DrawText(1,1,"Index = " +Str(n)+"  ......"+Str(MP_CountVertices(newcyl))+",   "+Str(MP_CountTriangles(newcyl))+",   "+MP_CountSurfaces(newcyl))
  MP_RenderWorld()
  MP_Flip()
Wend
applePi
Addict
Addict
Posts: 1404
Joined: Sun Jun 25, 2006 7:28 pm

Re: MP3D Engine Alpha 32

Post by applePi »

i think i know now how the faces (triangles) connected in the Psychophanta triangular open cylinder above.
the vertices are this ( as shown by the jumping sphere):
Image

we first write:

Code: Select all

Structure MyVertex 
  indx.l
EndStructure 
then

Code: Select all

Dim Vert.MyVertex (36)
MP_GetMeshData(newcyl, #PB_Mesh_Face,@Vert(),vertexlenght * vertexcount)
For i=0 To 35 Step 3
  Debug Str(vert(i)\indx)+" "+Str(vert(i+1)\indx)+" "+Str(vert(i+2)\indx) 
Next
we get:
5 1 4
4 1 0
6 2 5
5 2 1
7 3 6
6 3 2
9 5 8
8 5 4
10 6 9
9 6 5
11 7 10
10 7 6

so connect every 3 numbers with lines and we get the triangular open cylinder, i have tried by pencil a few triangles and it is correct.

Code: Select all

Structure MyVertex 
  indx.l
  
EndStructure 
    
MP_Graphics3D(640,480,0,3)
SetWindowTitle(0,"3D with new cylinder")
MP_Wireframe(1)
camera=MP_CreateCamera():MP_PositionEntity(camera,0,7,-12)
MP_EntityLookAt(camera, 0,0,0)
MP_CameraViewPort(camera, 0, 0, 600, 600 , RGB(100,100,0))

light=MP_CreateLight(1) 
MP_LightSetColor (light, RGB(0, 255, 0))

MP_PositionEntity(light,0,10,-2)
MP_EntityLookAt(light, 0,0,0)
;MP_Createcylinder(radius.f,height.f[,radius2.f,numSegBase,numSegHeight,close])
newcyl=MP_CreateCylinder(3,4,1.5,3,2,0)
MP_PositionEntity(newcyl,0,0,0)

MP_TurnEntity(newcyl,0,0,0)
sphere = MP_CreateSphere(16): MP_ScaleMesh(sphere, 0.1, 0.1, 0.1)
vertexcount = MP_CountVertices(newcyl)
vertexlenght = MP_GetMeshInfo (newcyl, 64)

Dim Vert.MyVertex (36)
MP_GetMeshData(newcyl, #PB_Mesh_Face,@Vert(),vertexlenght * vertexcount)
For i=0 To 35 Step 3
  Debug Str(vert(i)\indx)+" "+Str(vert(i+1)\indx)+" "+Str(vert(i+2)\indx) 
Next

n=-1
While MP_KeyDown(#PB_Key_Escape)=0 And WindowEvent()<>#PB_Event_CloseWindow
  If MP_Keydown(#PB_Key_Space)
    ;MP_TurnEntity(newcyl,0.0,1,0)
    MP_RotateMesh(newcyl, 0.0,1,0)
    MP_GetMeshData(newcyl, #PB_Mesh_Face,@Vert(),vertexlenght * vertexcount)
  EndIf
 
  
  MP_DrawText(1,1,Str(MP_CountVertices(newcyl))+",   "+Str(MP_CountTriangles(newcyl))+",   "+MP_CountSurfaces(newcyl))
  MP_RenderWorld()
  MP_Flip()
Wend
mpz
Enthusiast
Enthusiast
Posts: 494
Joined: Sat Oct 11, 2008 9:07 pm
Location: Germany, Berlin > member German forum

Re: MP3D Engine Alpha 32

Post by mpz »

Hi to all,

@Psychophanta, i like your Rotate_3DVector_by_Angle_adding(*fi.Vector3D,*R0.Vector3D). It look good to manipulate meshs. I will test this for that

@applePi, Whau your code is good an show how easy it is to get the vertex infos. I have changed a little bit the code to solve the "crash problem"

@Psychophanta, the MP_CreateCylinder is made from a mathematic algorythmus. This code generate more vertex as needed, see

MP_CreateOpenCylinder(Radius.f, height.f, numSegBase=16, numSegHeight=1)

in the Demo before. Some vertex are double to create the "latest" triangles. Perhaps i find a way to optimised it (but this need time). Much other "Mesh" algorythmen do the same(more vertex and triangles), but are easy for handling.

Greetings Michael

solved crash problem

Code: Select all

Structure MyVertex
      x.f : y.f : z.f      ; vertices coordinates
      nx.f : ny.f : nz.f ; normal coordinates
      Color.l                  ; color
      u.f : v.f               ; texture coordinates
      ;u1.f : v1.f               ; texture coordinates 2
      ;u2.f : v2.f               ; texture coordinates 2
EndStructure
   
MP_Graphics3D(640,480,0,3)
SetWindowTitle(0,"3D with new cylinder")
MP_Wireframe(1)
camera=MP_CreateCamera():MP_PositionEntity(camera,0,7,-12)
MP_EntityLookAt(camera, 0,0,0)
MP_CameraViewPort(camera, 0, 0, 600, 600 , RGB(100,100,0))

;MP_CameraSetPerspective(camera, 45)
light=MP_CreateLight(1)
MP_LightSetColor (light, RGB(0, 255, 0))

MP_PositionEntity(light,0,10,-2)
MP_EntityLookAt(light, 0,0,0)
;MP_Createcylinder(radius.f,height.f[,radius2.f,numSegBase,numSegHeight,close])
newcyl=MP_CreateCylinder(3,4,1.5,3,2,0)
MP_PositionEntity(newcyl,0,0,0)

MP_TurnEntity(newcyl,0,0,0)
sphere = MP_CreateSphere(16): MP_ScaleMesh(sphere, 0.1, 0.1, 0.1)
vertexcount = MP_CountVertices(newcyl)
vertexlenght = MP_GetMeshInfo (newcyl, 64)
Dim Vert.MyVertex (vertexcount)
MP_GetMeshData(newcyl, #PB_Mesh_Vertex,@Vert(),vertexlenght * vertexcount)

n=-1
While MP_KeyDown(#PB_Key_Escape)=0 And WindowEvent()<>#PB_Event_CloseWindow
  If MP_Keydown(#PB_Key_Space)
    ;MP_TurnEntity(newcyl,0.0,1,0)
    MP_RotateMesh(newcyl, 0.0,1,0)
    MP_GetMeshData(newcyl, #PB_Mesh_Vertex,@Vert(),vertexlenght * vertexcount)
  EndIf
 
  If MP_KeyHit(#PB_Key_Z)
    n+1
    If n = vertexcount + 1
      n=-1
      MP_PositionEntity(sphere,0,0,0)
  Else  
    MP_PositionEntity(sphere,vert(n)\x,vert(n)\y,vert(n)\z)
  EndIf  
       
  EndIf
 
  MP_DrawText(1,1,"Index = " +Str(n)+"  ......"+Str(MP_CountVertices(newcyl))+",   "+Str(MP_CountTriangles(newcyl))+",   "+MP_CountSurfaces(newcyl))
  MP_RenderWorld()
  MP_Flip()
Wend
Working on - MP3D Library - PB 5.73 version ready for download
User avatar
Psychophanta
Addict
Addict
Posts: 4969
Joined: Wed Jun 11, 2003 9:33 pm
Location: Lípetsk, Russian Federation
Contact:

Re: MP3D Engine Alpha 32

Post by Psychophanta »

Hi everybody,
applePi wrote:i think i know now how the faces (triangles) connected in the Psychophanta triangular open cylinder above.
the vertices are this ( as shown by the jumping sphere):
Image
But in my code above (Torus arc) i don use 3, 7 and 11 vertex, because they are redundant.
Just try that code for example with line:
Tor.i=CreateTorusArc(3,2,1,1,2,#PI/8,0)
and adding line:
MP_DrawText(1,1,Str(MP_CountVertices(Tor))+", "+Str(MP_CountTriangles(Tor)))
before line MP_RenderWorld() in the main loop.
You will see 9 vertex and 12 triangles, just what the mesh has to have, no more.
By the way, good code to get triangle and vertex info in an easy and fast way.
Here it is the scheme algorythm i coded in that function "Torus arc":
Image
mpz wrote:@Psychophanta, i like your Rotate_3DVector_by_Angle_adding(*fi.Vector3D,*R0.Vector3D). It look good to manipulate meshs. I will test this for that
That function just use 2 vectors (one of them represents an angle) to rotate one of them. The calculation is the same indeed that use a rotation matrix, but i do it here without matrix, but only vectors.
So, since the calculation is the same (is not shorter nor larger) as with rotation matrix, you can use a matrix to rotate any position vector, but if you prefer to know how my function works, maybe this image is good (just tranlate the text to german):
Image
mpz wrote:the MP_CreateCylinder is made from a mathematic algorythmus. This code generate more vertex as needed
Aha! that's the answer i wanted to hear.
So, can we say those algorithms which build meshes (from microsoft DX3D for example) are not as good as they should?

Thanks and greetings!
http://www.zeitgeistmovie.com

While world=business:world+mafia:Wend
Will never leave this forum until the absolute bugfree PB :mrgreen:
applePi
Addict
Addict
Posts: 1404
Joined: Sun Jun 25, 2006 7:28 pm

Re: MP3D Engine Alpha 32

Post by applePi »

Psychophanta, your CreateTorusArc http://purebasic.fr/english/viewtopic.p ... 60#p481492 is extra ordinary, thanks, i haven't recognized its importance from the first run, and haven't seen at first the right click mouse proc to drag the shape and see it better.
i don't understand its mathematics but i appreciate the shapes it is producing such as torus, half torus, pipes, horn , etc etc. some of the shapes i like is this
Tor.i=CreateTorusArc(16,30,1, 0.2, 2,1.8*#PI,0)
Tor.i=CreateTorusArc(25,5,0.4,0.2,2,#PI,0)
Image
User avatar
Psychophanta
Addict
Addict
Posts: 4969
Joined: Wed Jun 11, 2003 9:33 pm
Location: Lípetsk, Russian Federation
Contact:

Re: MP3D Engine Alpha 32

Post by Psychophanta »

applePi wrote:Psychophanta, your CreateTorusArc http://purebasic.fr/english/viewtopic.p ... 60#p481492 is extra ordinary, thanks, i haven't recognized its importance from the first run, and haven't seen at first the right click mouse proc to drag the shape and see it better.
i don't understand its mathematics but i appreciate the shapes it is producing such as torus, half torus, pipes, horn , etc etc. some of the shapes i like is this
Tor.i=CreateTorusArc(16,30,1, 0.2, 2,1.8*#PI,0)
Tor.i=CreateTorusArc(25,5,0.4,0.2,2,#PI,0)
Image
Thanks! :)
I want to port it to Ogre-PB. When i have at least 10 free minutes.
http://www.zeitgeistmovie.com

While world=business:world+mafia:Wend
Will never leave this forum until the absolute bugfree PB :mrgreen:
Post Reply