La plupart des moteur ou logiciel de modélisation 3D propose la création d'un torus, un cone et d'une pyramide sauf Ogre3D.
Depuis ce matin, StarBootics sur le forum anglais propose la création d'un torus.
C'est un sujet que vous pouvez suivre sur ce lien.
http://www.purebasic.fr/english/viewtop ... 36&t=61370
Cone, Torus & Pyramid
- falsam
- Messages : 7244
- Inscription : dim. 22/août/2010 15:24
- Localisation : IDF (Yvelines)
- Contact :
Cone, Torus & Pyramid
Dernière modification par falsam le mer. 07/janv./2015 12:05, modifié 1 fois.
Configuration : Windows 11 Famille 64-bit - PB 6.03 x64 - AMD Ryzen 7 - 16 GO RAM
Vidéo NVIDIA GeForce GTX 1650 Ti - Résolution 1920x1080 - Mise à l'échelle 125%
Vidéo NVIDIA GeForce GTX 1650 Ti - Résolution 1920x1080 - Mise à l'échelle 125%
- falsam
- Messages : 7244
- Inscription : dim. 22/août/2010 15:24
- Localisation : IDF (Yvelines)
- Contact :
Cone, Torus & Pyramid
J'ai testé le rendu de la création d'un torus. C'est pas mal du tout mais il y a un souci de réception de la lumière sur le torus comme vous pouvez le voir avec ce code ou j'ai placé un cube, une sphére et un torus.
Code : Tout sélectionner
Enumeration
#Mainform
EndEnumeration
Global Event
Macro LinearlySpacedValue(IncrementID, IncrementMax, MinValue, MaxValue)
((MinValue) + ((MaxValue) - (MinValue)) * ((IncrementID) / (IncrementMax)))
EndMacro
;CreateTorus() - By StarBootics
Macro CalculateTorusVertex(MinorRadius, MajorRadius, Uxx, Vxx)
MeshVertexPosition((MajorRadius + MinorRadius * Cos(Vxx)) * Cos(Uxx), (MajorRadius + MinorRadius * Cos(Vxx)) * Sin(Uxx), MinorRadius * Sin(Vxx))
MeshVertexTextureCoordinate(Uxx / (2*#PI), Vxx / (2*#PI))
MeshVertexNormal(0,1, 0)
EndMacro
Procedure CreateTorus(MeshID, MinorRadius.f, MajorRadius.f, Meridian = 32, Parallel = 32)
Protected MeshHandle, P00, P01, P02, P03, MeridianID, U00.d, U01.d, ParallelID, V00.d, V01.d
MeshHandle = CreateMesh(MeshID, #PB_Mesh_TriangleList, #PB_Mesh_Dynamic)
If MeshID = #PB_Any
MeshID = MeshHandle
EndIf
If IsMesh(MeshID)
AddSubMesh()
If Meridian < 3
Meridian = 3
EndIf
If Parallel < 3
Parallel = 3
EndIf
P00 = 0
P01 = P00 + 1
P02 = P01 + 1
P03 = P02 + 1
For MeridianID = 0 To Meridian - 1
U00 = LinearlySpacedValue(MeridianID, Meridian, 0.0, 2.0 * #PI)
U01 = LinearlySpacedValue(MeridianID + 1, Meridian, 0.0, 2.0 * #PI)
For ParallelID = 0 To Parallel - 1
V00 = LinearlySpacedValue(ParallelID, Parallel, 0.0, 2.0 * #PI)
V01 = LinearlySpacedValue(ParallelID + 1, Parallel, 0.0, 2.0 * #PI)
CalculateTorusVertex(MinorRadius, MajorRadius, U00, V00) ; P00
CalculateTorusVertex(MinorRadius, MajorRadius, U01, V00) ; P01
CalculateTorusVertex(MinorRadius, MajorRadius, U01, V01) ; P02
CalculateTorusVertex(MinorRadius, MajorRadius, U00, V01) ; P03
MeshFace(P00, P01, P02)
MeshFace(P02, P03, P00)
P00 = P03 + 1
P01 = P00 + 1
P02 = P01 + 1
P03 = P02 + 1
Next
Next
NormalizeMesh(MeshID, 0)
BuildMeshTangents(MeshID)
FinishMesh(#True)
EndIf
ProcedureReturn MeshID
EndProcedure
InitEngine3D()
InitKeyboard()
InitSprite()
InitMouse()
OpenWindow(#Mainform, 0, 0, 1024, 768, "Create Torus", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
OpenWindowedScreen(WindowID(#Mainform),0, 0, 1024, 768)
KeyboardMode(#PB_Keyboard_International)
;Light & Shadow
AmbientColor(RGB(127, 127, 127))
CreateLight(#PB_Any,RGB(151, 251, 151), -4, 50, 5)
WorldShadows(#PB_Shadow_Additive)
;Camera
Camera = CreateCamera(#PB_Any,0,0,100,100)
CameraBackColor(Camera, RGB(145, 182, 201))
MoveCamera(Camera, 10, 10, 15, #PB_Absolute)
CameraLookAt(Camera, 0,0,0)
;Material
Add3DArchive(#PB_Compiler_Home + "Examples/3D/Data/Textures", #PB_3DArchive_FileSystem)
CreateMaterial(0, TextureID(LoadTexture(#PB_Any, "Dirt.jpg")))
CreateMaterial(1, TextureID(LoadTexture(#PB_Any, "MRAMOR6X6.jpg")))
;Entities
CreateEntity(#PB_Any, MeshID(CreatePlane(#PB_Any, 30, 30, 10, 10, 5, 5)), MaterialID(0))
CreateEntity(#PB_Any, MeshID(CreateCube(#PB_Any, 4)), MaterialID(1), -6, 3, 0)
CreateEntity(#PB_Any, MeshID(CreateSphere(#PB_Any, 2)), MaterialID(1), 0, 3, 0)
CreateEntity(#PB_Any, MeshID(CreateTorus(#PB_Any, 1, 2)), MaterialID(1), 6, 3, 0)
Repeat
Repeat
Event = WindowEvent()
Select Event
Case #PB_Event_CloseWindow
End
EndSelect
Until Event = 0
If ExamineKeyboard()
If KeyboardPushed (#PB_Key_Escape)
Break
EndIf
EndIf
RenderWorld(80)
FlipBuffers()
ForEver
Dernière modification par falsam le mer. 07/janv./2015 21:24, modifié 1 fois.
Configuration : Windows 11 Famille 64-bit - PB 6.03 x64 - AMD Ryzen 7 - 16 GO RAM
Vidéo NVIDIA GeForce GTX 1650 Ti - Résolution 1920x1080 - Mise à l'échelle 125%
Vidéo NVIDIA GeForce GTX 1650 Ti - Résolution 1920x1080 - Mise à l'échelle 125%
- falsam
- Messages : 7244
- Inscription : dim. 22/août/2010 15:24
- Localisation : IDF (Yvelines)
- Contact :
Re: Cone, Torus & Pyramid
Correction du code pour un meilleur rendu lumineux. Cette solution est fourni par Samuel sur le forum anglais
Configuration : Windows 11 Famille 64-bit - PB 6.03 x64 - AMD Ryzen 7 - 16 GO RAM
Vidéo NVIDIA GeForce GTX 1650 Ti - Résolution 1920x1080 - Mise à l'échelle 125%
Vidéo NVIDIA GeForce GTX 1650 Ti - Résolution 1920x1080 - Mise à l'échelle 125%