Accueil > > > CUBE 3D DESSINER AVEC SOURIS (3DSMAX) SANS DIRECTX NI OPENGL
CUBE 3D DESSINER AVEC SOURIS (3DSMAX) SANS DIRECTX NI OPENGL
Information sur la source
Description
Ce code dessine un cube en 3d dans un plan incliner (tt ds la photo). Le code peut etre largement optimiser et surtout améliorer (pas de temps ces jours :( ). C'etait juste pour dire "c'est faisable avec vb sans Directx pour qlq mecs qui programment en c/c++ :p ". La meme méthode peut etre utilisee pour les autres formes (pyramide ...). Pour la coloration des faces de tube (les faces de tubes dans tt les sens), j'ai presque rien fais (faute 2 temps), mais j'ai donne la méthode a utiliser, reste juste faire qlq conditions avec les autres sens 2 la souris etc.. ;). Avant me penche sur la suite de cette source, j'aimerais savoir vos commentaires (des autres idees si possible), merci d'avance...
Source
- 'code tres simple mais éfficace :p
- 'davidauche@icqmail.com
-
-
- Private Type COORD
- X As Long
- Y As Long
- End Type
- Dim poly(1 To 4) As COORD
- Dim poly1(1 To 4) As COORD
- Dim poly2(1 To 4) As COORD
- Dim poly3(1 To 4) As COORD
- Dim poly4(1 To 4) As COORD
- Dim Xdepart1, Ydepart1 As Integer
- Dim NumCoords As Long
- Dim value As Integer
- Dim hBrush As Long, hRgn As Long
- Private Declare Function Polygon Lib "gdi32" (ByVal hdc As Long, lpPoint As Any, ByVal nCount As Long) As Long
- Private Declare Function CreatePolygonRgn Lib "gdi32" (lpPoint As Any, ByVal nCount As Long, ByVal nPolyFillMode As Long) As Long
- Private Declare Function FillRgn Lib "gdi32" (ByVal hdc As Long, ByVal hRgn As Long, ByVal hBrush As Long) As Long
- Private Declare Function GetStockObject Lib "gdi32" (ByVal nIndex As Long) As Long
- Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
- Const ALTERNATE = 1
- Const WINDING = 2
- Const BLACKBRUSH = 3
-
- Private Sub CubeBase(ByVal Xdepart As Integer, ByVal Ydepart As Integer, ByVal Xfinal As Integer, ByVal Yfinal As Integer, ByVal AngleRot As Integer, Couleur As OLE_COLOR)
- On Error Resume Next
-
- pi = 4 * Atn(1)
- NumCoords = 4
-
- z = Sqr((Xfinal - Xdepart) ^ 2 + (Yfinal - Ydepart) ^ 2)
-
- If Xfinal >= Xdepart Then
- cosA = (Yfinal - Ydepart) / z
- angle = Atn(Sqr(1 - cosA ^ 2) / cosA) * 180 / pi
-
- If Yfinal = Ydepart Then AngleA = AngleRot Else AngleA = 90 - AngleRot - angle
- longeur = z * Cos(AngleA * pi / 180)
- longeur2 = z * Sin(AngleA * pi / 180)
-
- Me.Cls
- X1 = longeur * Cos(AngleRot * pi / 180)
- Y1 = longeur * Sin(AngleRot * pi / 180)
- X2 = longeur2 * Sin(AngleRot * pi / 180)
- Y2 = longeur2 * Cos(AngleRot * pi / 180)
-
- If Yfinal > Ydepart Then
- poly(1).X = Xdepart: poly(1).Y = Ydepart
- poly(4).X = Xdepart + X1: poly(4).Y = Ydepart + Y1
- poly(3).X = Xfinal: poly(3).Y = Yfinal
- poly(2).X = Xdepart - X2: poly(2).Y = Ydepart + Y2
-
- Me.ForeColor = Couleur
- Polygon Me.hdc, poly(1), NumCoords
- Else
- If Yfinal < Ydepart Then
- poly(1).X = Xdepart: poly(1).Y = Ydepart
- poly(4).X = Xdepart - X1: poly(4).Y = Ydepart - Y1
- poly(3).X = Xfinal: poly(3).Y = Yfinal
- poly(2).X = Xdepart + X2: poly(2).Y = Ydepart - Y2
-
- Me.ForeColor = Couleur
- Polygon Me.hdc, poly(1), NumCoords
- Else
- poly(1).X = Xdepart: poly(1).Y = Ydepart
- poly(4).X = Xdepart + X1: poly(4).Y = Ydepart + Y1
- poly(3).X = Xfinal: poly(3).Y = Yfinal
- poly(2).X = Xdepart + X2: poly(2).Y = Ydepart - Y2
-
- Me.ForeColor = Couleur
- Polygon Me.hdc, poly(1), NumCoords
- End If
- End If
-
- Else
- cosA = Abs(Xfinal - Xdepart) / z
- angle = Atn(Sqr(1 - cosA ^ 2) / cosA) * 180 / pi
-
- If Yfinal > Ydepart Then AngleA = AngleRot + angle Else AngleA = angle - AngleRot
- longeur = z * Cos(AngleA * pi / 180)
- longeur2 = z * Sin(AngleA * pi / 180)
- X1 = longeur * Cos(AngleRot * pi / 180)
- Y1 = longeur * Sin(AngleRot * pi / 180)
- X2 = longeur2 * Cos((90 - AngleRot) * pi / 180)
- Y2 = longeur2 * Sin((90 - AngleRot) * pi / 180)
- Me.Cls
-
- If Yfinal > Ydepart Then
- poly(1).X = Xdepart: poly(1).Y = Ydepart
- poly(4).X = Xdepart - X1: poly(4).Y = Ydepart - Y1
- poly(3).X = Xfinal: poly(3).Y = Yfinal
- poly(2).X = Xdepart - X2: poly(2).Y = Ydepart + Y2
-
- Me.ForeColor = Couleur
- Polygon Me.hdc, poly(1), NumCoords
- Else
- poly(1).X = Xdepart: poly(1).Y = Ydepart
- poly(4).X = Xdepart - X1: poly(4).Y = Ydepart - Y1
- poly(3).X = Xfinal: poly(3).Y = Yfinal
- poly(2).X = Xdepart + X2: poly(2).Y = Ydepart - Y2
-
- Me.ForeColor = Couleur
- Polygon Me.hdc, poly(1), NumCoords
- End If
- End If
- End Sub
-
- Private Sub Command1_Click()
- value = 0
- Command1.Enabled = False: Command2.Enabled = True
- End Sub
-
- Private Sub Command2_Click()
- value = 0
- Command2.Enabled = False: Command1.Enabled = True
- End Sub
-
- Private Sub Form_Load()
- CubeBase 240, 0, 440, 528, 30, &HC0C0C0
- Me.AutoRedraw = True
- Polygon Me.hdc, poly(1), NumCoords
- Me.AutoRedraw = False
- Command1.Enabled = False
- Me.Caption = "Plan avec 30°"
- End Sub
-
- Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
- If value = 2 Then
- Me.AutoRedraw = True
- Polygon Me.hdc, poly1(1), 4
- Polygon Me.hdc, poly2(1), 4
- Polygon Me.hdc, poly3(1), 4
- Me.AutoRedraw = False
-
- If Command2.Enabled = False Then value = 0 Else value = 3
- End If
-
- If Button = 1 And value = 0 Then
- value = 1
- Xdepart1 = X: Ydepart1 = Y
- End If
-
- If Button = 2 Then value = 3: Command2.Enabled = True: Command1.Enabled = True
-
- End Sub
-
- Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
- If value = 3 Then Exit Sub
-
- If Button = 1 And value = 1 Then
- CubeBase Xdepart1, Ydepart1, X, Y, 30, vbRed
- End If
-
- If value = 2 Then
- CubeFin Y, vbRed
- End If
-
- End Sub
-
- Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
-
- If value = 3 Then Exit Sub
-
- Me.AutoRedraw = True
- Polygon Me.hdc, poly(1), NumCoords
- value = 2
- Me.AutoRedraw = False
-
- Command1.Enabled = True
- End Sub
- Private Sub CubeFin(ByVal Yfinal As Integer, Couleur As OLE_COLOR)
- Dim hauteur As Integer
-
- hauteur = poly(3).Y - Yfinal
-
- poly1(1).X = poly(1).X
- poly1(1).Y = poly(1).Y - hauteur
- poly1(2).X = poly(2).X
- poly1(2).Y = poly(2).Y - hauteur
- poly1(3).X = poly(3).X
- poly1(3).Y = poly(3).Y - hauteur
- poly1(4).X = poly(4).X
- poly1(4).Y = poly(4).Y - hauteur
-
- poly2(1) = poly(1)
- poly2(2) = poly(2)
- poly2(3) = poly1(2)
- poly2(4) = poly1(1)
-
- poly3(1) = poly(4)
- poly3(2) = poly(3)
- poly3(3) = poly1(3)
- poly3(4) = poly1(4)
-
- poly4(1) = poly(2)
- poly4(2) = poly(3)
- poly4(3) = poly1(3)
- poly4(4) = poly1(2)
-
- Me.Cls
-
-
- hBrush = GetStockObject(BLACKBRUSH)
- hRgn = CreatePolygonRgn(poly3(1), NumCoords, ALTERNATE)
- If hRgn Then FillRgn Me.hdc, hRgn, hBrush
- DeleteObject hRgn
-
- hRgn = CreatePolygonRgn(poly1(1), NumCoords, ALTERNATE)
- If hRgn Then FillRgn Me.hdc, hRgn, hBrush
- DeleteObject hRgn
-
- hRgn = CreatePolygonRgn(poly4(1), NumCoords, ALTERNATE)
- If hRgn Then FillRgn Me.hdc, hRgn, hBrush
- DeleteObject hRgn
-
- Polygon Me.hdc, poly1(1), 4
- Polygon Me.hdc, poly4(1), 4
- Polygon Me.hdc, poly3(1), 4
-
- End Sub
'code tres simple mais éfficace :p
'davidauche@icqmail.com
Private Type COORD
X As Long
Y As Long
End Type
Dim poly(1 To 4) As COORD
Dim poly1(1 To 4) As COORD
Dim poly2(1 To 4) As COORD
Dim poly3(1 To 4) As COORD
Dim poly4(1 To 4) As COORD
Dim Xdepart1, Ydepart1 As Integer
Dim NumCoords As Long
Dim value As Integer
Dim hBrush As Long, hRgn As Long
Private Declare Function Polygon Lib "gdi32" (ByVal hdc As Long, lpPoint As Any, ByVal nCount As Long) As Long
Private Declare Function CreatePolygonRgn Lib "gdi32" (lpPoint As Any, ByVal nCount As Long, ByVal nPolyFillMode As Long) As Long
Private Declare Function FillRgn Lib "gdi32" (ByVal hdc As Long, ByVal hRgn As Long, ByVal hBrush As Long) As Long
Private Declare Function GetStockObject Lib "gdi32" (ByVal nIndex As Long) As Long
Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
Const ALTERNATE = 1
Const WINDING = 2
Const BLACKBRUSH = 3
Private Sub CubeBase(ByVal Xdepart As Integer, ByVal Ydepart As Integer, ByVal Xfinal As Integer, ByVal Yfinal As Integer, ByVal AngleRot As Integer, Couleur As OLE_COLOR)
On Error Resume Next
pi = 4 * Atn(1)
NumCoords = 4
z = Sqr((Xfinal - Xdepart) ^ 2 + (Yfinal - Ydepart) ^ 2)
If Xfinal >= Xdepart Then
cosA = (Yfinal - Ydepart) / z
angle = Atn(Sqr(1 - cosA ^ 2) / cosA) * 180 / pi
If Yfinal = Ydepart Then AngleA = AngleRot Else AngleA = 90 - AngleRot - angle
longeur = z * Cos(AngleA * pi / 180)
longeur2 = z * Sin(AngleA * pi / 180)
Me.Cls
X1 = longeur * Cos(AngleRot * pi / 180)
Y1 = longeur * Sin(AngleRot * pi / 180)
X2 = longeur2 * Sin(AngleRot * pi / 180)
Y2 = longeur2 * Cos(AngleRot * pi / 180)
If Yfinal > Ydepart Then
poly(1).X = Xdepart: poly(1).Y = Ydepart
poly(4).X = Xdepart + X1: poly(4).Y = Ydepart + Y1
poly(3).X = Xfinal: poly(3).Y = Yfinal
poly(2).X = Xdepart - X2: poly(2).Y = Ydepart + Y2
Me.ForeColor = Couleur
Polygon Me.hdc, poly(1), NumCoords
Else
If Yfinal < Ydepart Then
poly(1).X = Xdepart: poly(1).Y = Ydepart
poly(4).X = Xdepart - X1: poly(4).Y = Ydepart - Y1
poly(3).X = Xfinal: poly(3).Y = Yfinal
poly(2).X = Xdepart + X2: poly(2).Y = Ydepart - Y2
Me.ForeColor = Couleur
Polygon Me.hdc, poly(1), NumCoords
Else
poly(1).X = Xdepart: poly(1).Y = Ydepart
poly(4).X = Xdepart + X1: poly(4).Y = Ydepart + Y1
poly(3).X = Xfinal: poly(3).Y = Yfinal
poly(2).X = Xdepart + X2: poly(2).Y = Ydepart - Y2
Me.ForeColor = Couleur
Polygon Me.hdc, poly(1), NumCoords
End If
End If
Else
cosA = Abs(Xfinal - Xdepart) / z
angle = Atn(Sqr(1 - cosA ^ 2) / cosA) * 180 / pi
If Yfinal > Ydepart Then AngleA = AngleRot + angle Else AngleA = angle - AngleRot
longeur = z * Cos(AngleA * pi / 180)
longeur2 = z * Sin(AngleA * pi / 180)
X1 = longeur * Cos(AngleRot * pi / 180)
Y1 = longeur * Sin(AngleRot * pi / 180)
X2 = longeur2 * Cos((90 - AngleRot) * pi / 180)
Y2 = longeur2 * Sin((90 - AngleRot) * pi / 180)
Me.Cls
If Yfinal > Ydepart Then
poly(1).X = Xdepart: poly(1).Y = Ydepart
poly(4).X = Xdepart - X1: poly(4).Y = Ydepart - Y1
poly(3).X = Xfinal: poly(3).Y = Yfinal
poly(2).X = Xdepart - X2: poly(2).Y = Ydepart + Y2
Me.ForeColor = Couleur
Polygon Me.hdc, poly(1), NumCoords
Else
poly(1).X = Xdepart: poly(1).Y = Ydepart
poly(4).X = Xdepart - X1: poly(4).Y = Ydepart - Y1
poly(3).X = Xfinal: poly(3).Y = Yfinal
poly(2).X = Xdepart + X2: poly(2).Y = Ydepart - Y2
Me.ForeColor = Couleur
Polygon Me.hdc, poly(1), NumCoords
End If
End If
End Sub
Private Sub Command1_Click()
value = 0
Command1.Enabled = False: Command2.Enabled = True
End Sub
Private Sub Command2_Click()
value = 0
Command2.Enabled = False: Command1.Enabled = True
End Sub
Private Sub Form_Load()
CubeBase 240, 0, 440, 528, 30, &HC0C0C0
Me.AutoRedraw = True
Polygon Me.hdc, poly(1), NumCoords
Me.AutoRedraw = False
Command1.Enabled = False
Me.Caption = "Plan avec 30°"
End Sub
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If value = 2 Then
Me.AutoRedraw = True
Polygon Me.hdc, poly1(1), 4
Polygon Me.hdc, poly2(1), 4
Polygon Me.hdc, poly3(1), 4
Me.AutoRedraw = False
If Command2.Enabled = False Then value = 0 Else value = 3
End If
If Button = 1 And value = 0 Then
value = 1
Xdepart1 = X: Ydepart1 = Y
End If
If Button = 2 Then value = 3: Command2.Enabled = True: Command1.Enabled = True
End Sub
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If value = 3 Then Exit Sub
If Button = 1 And value = 1 Then
CubeBase Xdepart1, Ydepart1, X, Y, 30, vbRed
End If
If value = 2 Then
CubeFin Y, vbRed
End If
End Sub
Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
If value = 3 Then Exit Sub
Me.AutoRedraw = True
Polygon Me.hdc, poly(1), NumCoords
value = 2
Me.AutoRedraw = False
Command1.Enabled = True
End Sub
Private Sub CubeFin(ByVal Yfinal As Integer, Couleur As OLE_COLOR)
Dim hauteur As Integer
hauteur = poly(3).Y - Yfinal
poly1(1).X = poly(1).X
poly1(1).Y = poly(1).Y - hauteur
poly1(2).X = poly(2).X
poly1(2).Y = poly(2).Y - hauteur
poly1(3).X = poly(3).X
poly1(3).Y = poly(3).Y - hauteur
poly1(4).X = poly(4).X
poly1(4).Y = poly(4).Y - hauteur
poly2(1) = poly(1)
poly2(2) = poly(2)
poly2(3) = poly1(2)
poly2(4) = poly1(1)
poly3(1) = poly(4)
poly3(2) = poly(3)
poly3(3) = poly1(3)
poly3(4) = poly1(4)
poly4(1) = poly(2)
poly4(2) = poly(3)
poly4(3) = poly1(3)
poly4(4) = poly1(2)
Me.Cls
hBrush = GetStockObject(BLACKBRUSH)
hRgn = CreatePolygonRgn(poly3(1), NumCoords, ALTERNATE)
If hRgn Then FillRgn Me.hdc, hRgn, hBrush
DeleteObject hRgn
hRgn = CreatePolygonRgn(poly1(1), NumCoords, ALTERNATE)
If hRgn Then FillRgn Me.hdc, hRgn, hBrush
DeleteObject hRgn
hRgn = CreatePolygonRgn(poly4(1), NumCoords, ALTERNATE)
If hRgn Then FillRgn Me.hdc, hRgn, hBrush
DeleteObject hRgn
Polygon Me.hdc, poly1(1), 4
Polygon Me.hdc, poly4(1), 4
Polygon Me.hdc, poly3(1), 4
End Sub
Conclusion
j'ai bien amuse avec les calculs math pour dessiner des rectangles avec un plan incliner :-).
Historique
- 22 février 2005 02:02:36 :
- Ajouter capture
Sources du même auteur
Sources de la même categorie
Commentaires et avis
|
Derniers Blogs
SESSION SILVERLIGHT 5 3D : SLIDES ET DEMOSSESSION SILVERLIGHT 5 3D : SLIDES ET DEMOS par Groc
Durant les techdays, j'ai eu le plaisir d'animer une session sur Silverlight 5 et la 3D avec Simon Ferquel. Comme promis, voici nos slides et mes démos (celles avec le viper BSG) ici et là. Pour mémoire, les démos utilisent toutes le viper BSG...
Cliquez pour lire la suite de l'article par Groc [TECHDAYS 2012] SESSION WEBMATRIX 2 : LE COUTEAU SUISSE GRATUIT POUR VOS DéVELOPPEMENTS WEB - SLIDES[TECHDAYS 2012] SESSION WEBMATRIX 2 : LE COUTEAU SUISSE GRATUIT POUR VOS DéVELOPPEMENTS WEB - SLIDES par gpommier
Suite à la session que j'ai présenté sur WebMatrix 2, vous pouvez trouver les slides ici, ainsi que les démos en packages nuget : démos1 et démos2 J'en profite pour remercier chaleureusement tous ceux qui sont venus très nombreux à cette sess...
Cliquez pour lire la suite de l'article par gpommier [SHAREPOINT] LES SESSIONS TECHDAYS 2012.[SHAREPOINT] LES SESSIONS TECHDAYS 2012. par Patrick Guimonet
Voici donc pour ceux qui n'ont pas pu venir, ou ceux qui n'ont pas pu toutes les suivre la liste des sessions SharePoint aux TechDays 2012, que je mettrais à jour dès que les liens des vidéo seront disponibles. Ou ici : http...
Cliquez pour lire la suite de l'article par Patrick Guimonet TECHDAYS PARIS 2012 : SESSION PLEINIèRE JOUR 3TECHDAYS PARIS 2012 : SESSION PLEINIèRE JOUR 3 par ROMELARD Fabrice
Speaker: Bernard Ourghanlian Cette session est comme chaque jour transmise en live par BrainSonic, et j'ai donc suivi cette troisième pleinière par ce moyen sur mon iPad . Elle est dédiée comme chaque année à la mise en perspective de l'é...
Cliquez pour lire la suite de l'article par ROMELARD Fabrice MISHRA READER : UN LECTEUR RSS TRèS ZUNE STYLE EN OPEN SOURCE !MISHRA READER : UN LECTEUR RSS TRèS ZUNE STYLE EN OPEN SOURCE ! par Vko
Hier durant une session dédiée aux Techdays 2012, j'ai eu le plaisir d'annoncer la sortie de la Béta 2 de Mishra Reader. C'est quoi ? Pour les utilisateurs, c'est une vraie expérience de lecture de flux RSS sur Windows. Rien à voir avec les produit...
Cliquez pour lire la suite de l'article par Vko
Logiciels
Tribler (2012)TRIBLER (2012)Tribler est un client pair à pair (P2P/Peer-to-Peer) open source avec la capacité de regarder des... Cliquez pour télécharger Tribler OneSwarm (2012)ONESWARM (2012)Le peer-to-peer qui protège votre vie privée, c'est OneSwarm.
Ce logiciel de peer-to-peer crypté... Cliquez pour télécharger OneSwarm PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO (V8.4)PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO (V8.4)PONAMEDIA TV DEVIENS HELLLOOO FLASH
LA TV SUR VOTRE ORDINATEUR.
Toute une plateforme Multi... Cliquez pour télécharger PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO Academy System (17.2.1.0)ACADEMY SYSTEM (17.2.1.0)Logiciel de gestion des établissements.
- élèves/étudiants (inscription, dossier, absence...)
-... Cliquez pour télécharger Academy System Easy-Planning (1.0.0.1)EASY-PLANNING (1.0.0.1)Basé sur les mêmes principes que MyPlanning, Easy-Planning permet de créer des plannings sous la ... Cliquez pour télécharger Easy-Planning
|