Du bist nicht angemeldet.

Stilllegung des Forums
Das Forum wurde am 05.06.2023 nach über 20 Jahren stillgelegt (weitere Informationen und ein kleiner Rückblick).
Registrierungen, Anmeldungen und Postings sind nicht mehr möglich. Öffentliche Inhalte sind weiterhin zugänglich.
Das Team von spieleprogrammierer.de bedankt sich bei der Community für die vielen schönen Jahre.
Wenn du eine deutschsprachige Spieleentwickler-Community suchst, schau doch mal im Discord und auf ZFX vorbei!

Werbeanzeige

Anonymous

unregistriert

1

20.06.2005, 13:49

Maus soll auf mesh zugreifen können (c# + SDk dx9)

Ich habe jetzt endlich den Würfel von 5*5*5 meshBoxen erstellt.

nun möchte ich gerne mit der Maus die einzelnen meshboxen anklicken können. ???

Hier ist mein Code in c#

Quellcode

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
using System;
using System.Windows.Forms;
using System.Drawing;
using Microsoft.DirectX;
using Microsoft.DirectX.Direct3D;
using Microsoft.DirectX.DirectInput;
using System.Threading;

// Namspace für den Würfel
namespace Wuerfel
{
    // Klasse für den Würfel
    public class Form1 :  System.Windows.Forms.Form
    {
        PresentParameters presentParams;
        System.Windows.Forms.Timer myTimer = new System.Windows.Forms.Timer ();
        delegate void UIDelegate();
        static Microsoft.DirectX.Direct3D.Device device = null;
        static float xAngle, yAngle, zAngle ;
        private Vector3 v3CurrMeshPos = new Vector3();
        static int i=0;
        // Deklaration der Würfelmatrix
        static Mesh[] meshBox = new Mesh[126];
        static Matrix[] mBox = new Matrix[126];
        //============================================================================================  
        
        static void Main() 
        { 
            Application.Run(new Form1());
            
        }
        //============================================================================================      
        
        public static void mBoxebene()
        { 
            float e = -1.6f;
            float f =  0.0f;
            i=0;
            int l=0;
            while(i<125)
            {   
                while(l<25)
                {
                    mBox[i]=Matrix.Translation( new Vector3(-1.6f,e,f));
                    i++;
                    mBox[i]=Matrix.Translation( new Vector3(-0.8f,e,f));
                    i++;
                    mBox[i]=Matrix.Translation( new Vector3( 0.0f,e,f));
                    i++;
                    mBox[i]=Matrix.Translation( new Vector3( 0.8f,e,f));
                    i++;
                    mBox[i]=Matrix.Translation( new Vector3( 1.6f,e,f));
                    e = e + 0.8f;
                    i++;
                    l=l+5;  
                }
                l=0;
                e = -1.6f;
                f=f+1.5f;
            }
        }
        //============================================================================================
        
        public Form1()
        {
            Text = "KDE Würfel ";
            myTimer.Tick += new EventHandler( OnTimer );
            myTimer.Interval = 2;
            ClientSize = new Size( 800, 600 );
        }
        //============================================================================================
        
        protected override void OnResize( System.EventArgs e )
        {   
            myTimer.Stop();
            try
            {   
                i=0;
                presentParams = new PresentParameters();
                presentParams.Windowed = true;                 
                presentParams.SwapEffect = SwapEffect.Discard; 
                presentParams.EnableAutoDepthStencil = true;   
                presentParams.AutoDepthStencilFormat = DepthFormat.D16; 
            
                if ( device != null ) device.Dispose();
                device = new Microsoft.DirectX.Direct3D.Device( 0, Microsoft.DirectX.Direct3D.DeviceType.Hardware,                                                                                      
                    this,CreateFlags.SoftwareVertexProcessing, presentParams );
                
                while(i<125)
                {
                    if ( meshBox[i] != null ) meshBox[i].Dispose();
                    i++;
                }
                //Die Form vom Würfel 
                i=0;
                while(i<=125)
                {
                    meshBox[i]  = Mesh.Box ( device, 0.5f, 0.5f, 0.5f ); 
                    i++;
                }
                
                // Optic des Würfels
                Material myMaterial = new Material();
                myMaterial.Diffuse = myMaterial.Ambient = Color.Gold;
                device.Material = myMaterial;
            
                //Lichtverhältnisse des Würfels
                device.Lights[0].Type = LightType.Spot;
                device.Lights[0].Diffuse = Color.Green;
                device.Lights[0].Direction = new Vector3( 0, 0, 7 );
                device.Lights[0].Enabled = true;
                
                // Einstellug des Blickwinkels
                device.Transform.View = Matrix.LookAtLH(
                    new Vector3( 0f, 0f, -6.0f ),   //Augenpunkt 5.0 vor dem canvas
                    new Vector3( 0f, 0f,  -1f ),   //Kammera sieht auf 0,0,0
                    new Vector3( 0f, 1.0f,  0f ) ); //world's up direction is the y-axis
                device.Transform.Projection = Matrix.PerspectiveFovLH( (float)Math.PI/4, 1f, 1f, 100f );
                device.RenderState.CullMode = Cull.None;
                device.RenderState.Lighting = true;
                xAngle = yAngle = zAngle = 1; 
                myTimer.Start(); 
            }
            catch (DirectXException) { MessageBox.Show("Could not initialize Direct3D." ); return; }
        }
        //============================================================================================
        
        protected static void OnTimer( Object myObject, EventArgs myEventArgs )
        {
            mBoxebene();
            
            if (device == null) return;
            device.Clear( ClearFlags.Target | ClearFlags.ZBuffer, Color.Honeydew, 5f, 0 );
            //In alle drei Richtungen rotieren
            Matrix m = Matrix.RotationYawPitchRoll( xAngle += 0.05f, yAngle += 0.05f, zAngle += 0.05f );
            //Würfel zeichnen
            device.BeginScene();
            i=0;
            while (i<125)
            {
                device.Transform.World  = m * mBox[i];  meshBox[i].DrawSubset( 0 );
                i++;
            }
            device.EndScene();
            device.Present();   
        }
//============================================================================================
        
    }// Ende der Klasse
}// Ende des Namespaces


Bitte Helft mir !! :huhu:

bassdscho

Alter Hase

Beiträge: 1 056

Wohnort: Heuchlingen

Beruf: Student - Technische Informatik

  • Private Nachricht senden

2

21.06.2005, 23:33

Hi,

ich kenn mich mit C# nicht so aus. Warum machst du 125 Translations Matrien? Da reicht doch eine für deine 125 Würfel.
Hier mal eine Ansatz wie du das anstellen kannst:
https://www.spieleprogrammierer.de/phpBB…3449&highlight=
Verlierer jammern immer von wegen ihr bestes!
Sieger gehen nach Hause und vögeln die Ballkönigin!

Anonymous

unregistriert

3

22.06.2005, 13:50

Leider weiß ich immer noch nicht wie ich das schaffe !!


??? ??? ???

bassdscho

Alter Hase

Beiträge: 1 056

Wohnort: Heuchlingen

Beruf: Student - Technische Informatik

  • Private Nachricht senden

4

22.06.2005, 17:20

was kapierst du nicht?
Das was in den Threads steht oder was anderes?
Verlierer jammern immer von wegen ihr bestes!
Sieger gehen nach Hause und vögeln die Ballkönigin!

Werbeanzeige