<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[[C++] struct in zweidimensionalem Array]]></title><description><![CDATA[<p>Hi!<br />
Ich bin an der Grenze zur Verzweiflung. Ich sitze seit einer Woche an einer Sache und komme trotzdem nicht weiter... Ich hab vorher fast zwei Jahre in Java programmiert und bin nun wegen opengl auf c++ umgestiegen.<br />
Das Problem:<br />
Ich benutze folgende Strukturen:</p>
<pre><code class="language-cpp">typedef struct{
		float x;
		float y;
f		float z;
} Vector;

typedef struct{
		Vector position;
		Vector normals[4]; 
		Vector coord[4];
		float height;
} Area;
</code></pre>
<p>Ich speichere die &quot;areas&quot; in einem Zweidimensionalem Array:</p>
<p>Area world[worldi][worldj]</p>
<p>Ausserdem habe ich ein zweites Array, wo die areas nach gewissen transformationen gehalten werden:</p>
<p>Area transWorld[worldi][worldj];</p>
<p>Initieert wird das worldArray folgendermassen:</p>
<pre><code class="language-cpp">GLvoid InitWorld(){
	InitRay(myRay);
	Area *tmpArea = NULL;
	Vector *tmpVector = NULL;
	for(int i = 0; i &lt; worldi; i++){
		for(int j = 0; j &lt; worldj; j++){
			tmpArea = &amp;world[i][j];
			if(map[i][j] == 1){
			tmpArea-&gt;position.x = i * areaSide;
			tmpArea-&gt;position.y = 0.0;
			tmpArea-&gt;position.z = j * areaSide;
			tmpVector = &amp;tmpArea-&gt;normals[0];
			tmpVector-&gt;x = 0.0f;
			tmpVector-&gt;y = 0.0f;
			tmpVector-&gt;z = -1.0f;
			tmpVector = &amp;tmpArea-&gt;normals[1];
			tmpVector-&gt;x = 1.0;
			tmpVector-&gt;y  = 0.0;
			tmpVector-&gt;z  = 0.0;
			tmpVector = &amp;tmpArea-&gt;normals[2];
			tmpVector-&gt;x = 0.0;
			tmpVector-&gt;y = 0.0;
			tmpVector-&gt;z = 1.0;
			tmpVector = &amp;tmpArea-&gt;normals[3];
			tmpVector-&gt;x = -1.0;
			tmpVector-&gt;y = 0.0;
			tmpVector-&gt;z = 0.0;
			tmpVector = &amp;tmpArea-&gt;coord[0];
			tmpVector-&gt;x = i * areaSide;
			tmpVector-&gt;y = 0.0;
			tmpVector-&gt;z = j * areaSide;
			tmpVector = &amp;tmpArea-&gt;coord[1];
			tmpVector-&gt;x = i * areaSide + areaSide;
			tmpVector-&gt;y = 0.0;
			tmpVector-&gt;z = j * areaSide;
			tmpVector = &amp;tmpArea-&gt;coord[2];
			tmpVector-&gt;x = i * areaSide + areaSide;
			tmpVector-&gt;y = 0.0;
			tmpVector-&gt;z = j * areaSide + areaSide;
			tmpVector = &amp;tmpArea-&gt;coord[3];
			tmpVector-&gt;x = i * areaSide;
			tmpVector-&gt;y = 0.0;
			tmpVector-&gt;z = j * areaSide + areaSide;
			}
		}
	}
}
</code></pre>
<p>Vor jeder gezeichenter Frame erfolgt ein update der Welt mittels:</p>
<pre><code class="language-cpp">GLvoid updateWorldCoord(){ 
	Area *tmpArea = NULL;
	Area *transArea = NULL;
	Vector *tmpVector = NULL;
	for(int i = 0; i &lt; worldi; i++){
		for(int j = 0; j &lt; worldj; j++){
			if(map[i][j] == 1){
				tmpArea = &amp;world[i][j];
				transArea = &amp;transWorld[i][j];
				//tmpVector = &amp;(tmpArea-&gt;position);
				transArea-&gt;position = rotateVector((tmpArea-&gt;position), (GLfloat)(360.0f - yrot), 1);
				transArea-&gt;position = translateVector((tmpArea-&gt;position), -xpos, 0.0, -zpos);
				for(int k = 0; k &lt; 4; k++){
					transArea-&gt;coord[k] = rotateVector((tmpArea-&gt;coord[k]), 360.0f - yrot, 1);
					transArea-&gt;coord[k] = translateVector((tmpArea-&gt;coord[k]), -xpos, 0.0, -zpos);
					transArea-&gt;normals[k] = rotateVector((tmpArea-&gt;normals[k]), 360.0f - yrot, 1);
					transArea-&gt;normals[k] = translateVector((tmpArea-&gt;normals[k]), -xpos, 0.0, -zpos);
				}
			}
		}
	}
}
</code></pre>
<p>Wenn ich nun nach dem Update die Daten zwecks collision-detection auslesen will, mit:<br />
(...)</p>
<pre><code class="language-cpp">Vector tempCoord;
	Vector tempNormal;
	Vector tempCoord2;
	Vector tempNormal2;
for(int ic = 0; ic &lt; worldi; ic++){
		for(int jc = 0; jc &lt;worldj; jc++){
			tmpArea = transWorld[ic][jc];
				for(int kc = 0; kc &lt; 4; kc++){
					tempCoord = tmpArea.coord[kc];
					tempNormal = tmpArea.normals[kc];
					tempCoord2 = tmpArea.coord[(kc+1)%4];
					tempNormal2 = tmpArea.normals[(kc+1)%4];
</code></pre>
<p>(...)</p>
<p>kommen total verwirrte Sachen raus!</p>
<p>Ich hab mir einen Breakpoint gesetzt und mir die Daten aus dem Debugger ausgelesen:<br />
Wenn ich mit der Maus über ic geh' - steht da &quot;ic = 10&quot;, wenn ich aber über jc geh' - steht da &quot;int jc&quot; !!!<br />
Als nächstes geh ich über tempCoord - da steht zB {123.4, 1.2, 12.3}<br />
im tempCoord2 steht das selbe!!!<br />
Und das beste ist: wenn ich mir angucke was im tempArea steht - ist alles auf 0.0 gesetzt!!!<br />
Da frag ich mich wie er dann auf die tempCoord Werte gekommen ist?!?! Wenn in der tmpArea nur 0.0 stehen?</p>
<p>Ich dahte das hätte was mit den call-by-value und call-by-refference zu tun, aber ich habe den Code nochaml umgeschrieben, damit es davon nicht abhängt - aber es geht weiter nicht...</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/139553/c-struct-in-zweidimensionalem-array</link><generator>RSS for Node</generator><lastBuildDate>Sun, 30 Aug 2026 12:36:18 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/139553.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 07 Mar 2006 16:04:10 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to [C++] struct in zweidimensionalem Array on Tue, 07 Mar 2006 17:36:52 GMT]]></title><description><![CDATA[<p>Hi!<br />
Ich bin an der Grenze zur Verzweiflung. Ich sitze seit einer Woche an einer Sache und komme trotzdem nicht weiter... Ich hab vorher fast zwei Jahre in Java programmiert und bin nun wegen opengl auf c++ umgestiegen.<br />
Das Problem:<br />
Ich benutze folgende Strukturen:</p>
<pre><code class="language-cpp">typedef struct{
		float x;
		float y;
f		float z;
} Vector;

typedef struct{
		Vector position;
		Vector normals[4]; 
		Vector coord[4];
		float height;
} Area;
</code></pre>
<p>Ich speichere die &quot;areas&quot; in einem Zweidimensionalem Array:</p>
<p>Area world[worldi][worldj]</p>
<p>Ausserdem habe ich ein zweites Array, wo die areas nach gewissen transformationen gehalten werden:</p>
<p>Area transWorld[worldi][worldj];</p>
<p>Initieert wird das worldArray folgendermassen:</p>
<pre><code class="language-cpp">GLvoid InitWorld(){
	InitRay(myRay);
	Area *tmpArea = NULL;
	Vector *tmpVector = NULL;
	for(int i = 0; i &lt; worldi; i++){
		for(int j = 0; j &lt; worldj; j++){
			tmpArea = &amp;world[i][j];
			if(map[i][j] == 1){
			tmpArea-&gt;position.x = i * areaSide;
			tmpArea-&gt;position.y = 0.0;
			tmpArea-&gt;position.z = j * areaSide;
			tmpVector = &amp;tmpArea-&gt;normals[0];
			tmpVector-&gt;x = 0.0f;
			tmpVector-&gt;y = 0.0f;
			tmpVector-&gt;z = -1.0f;
			tmpVector = &amp;tmpArea-&gt;normals[1];
			tmpVector-&gt;x = 1.0;
			tmpVector-&gt;y  = 0.0;
			tmpVector-&gt;z  = 0.0;
			tmpVector = &amp;tmpArea-&gt;normals[2];
			tmpVector-&gt;x = 0.0;
			tmpVector-&gt;y = 0.0;
			tmpVector-&gt;z = 1.0;
			tmpVector = &amp;tmpArea-&gt;normals[3];
			tmpVector-&gt;x = -1.0;
			tmpVector-&gt;y = 0.0;
			tmpVector-&gt;z = 0.0;
			tmpVector = &amp;tmpArea-&gt;coord[0];
			tmpVector-&gt;x = i * areaSide;
			tmpVector-&gt;y = 0.0;
			tmpVector-&gt;z = j * areaSide;
			tmpVector = &amp;tmpArea-&gt;coord[1];
			tmpVector-&gt;x = i * areaSide + areaSide;
			tmpVector-&gt;y = 0.0;
			tmpVector-&gt;z = j * areaSide;
			tmpVector = &amp;tmpArea-&gt;coord[2];
			tmpVector-&gt;x = i * areaSide + areaSide;
			tmpVector-&gt;y = 0.0;
			tmpVector-&gt;z = j * areaSide + areaSide;
			tmpVector = &amp;tmpArea-&gt;coord[3];
			tmpVector-&gt;x = i * areaSide;
			tmpVector-&gt;y = 0.0;
			tmpVector-&gt;z = j * areaSide + areaSide;
			}
		}
	}
}
</code></pre>
<p>Vor jeder gezeichenter Frame erfolgt ein update der Welt mittels:</p>
<pre><code class="language-cpp">GLvoid updateWorldCoord(){ 
	Area *tmpArea = NULL;
	Area *transArea = NULL;
	Vector *tmpVector = NULL;
	for(int i = 0; i &lt; worldi; i++){
		for(int j = 0; j &lt; worldj; j++){
			if(map[i][j] == 1){
				tmpArea = &amp;world[i][j];
				transArea = &amp;transWorld[i][j];
				//tmpVector = &amp;(tmpArea-&gt;position);
				transArea-&gt;position = rotateVector((tmpArea-&gt;position), (GLfloat)(360.0f - yrot), 1);
				transArea-&gt;position = translateVector((tmpArea-&gt;position), -xpos, 0.0, -zpos);
				for(int k = 0; k &lt; 4; k++){
					transArea-&gt;coord[k] = rotateVector((tmpArea-&gt;coord[k]), 360.0f - yrot, 1);
					transArea-&gt;coord[k] = translateVector((tmpArea-&gt;coord[k]), -xpos, 0.0, -zpos);
					transArea-&gt;normals[k] = rotateVector((tmpArea-&gt;normals[k]), 360.0f - yrot, 1);
					transArea-&gt;normals[k] = translateVector((tmpArea-&gt;normals[k]), -xpos, 0.0, -zpos);
				}
			}
		}
	}
}
</code></pre>
<p>Wenn ich nun nach dem Update die Daten zwecks collision-detection auslesen will, mit:<br />
(...)</p>
<pre><code class="language-cpp">Vector tempCoord;
	Vector tempNormal;
	Vector tempCoord2;
	Vector tempNormal2;
for(int ic = 0; ic &lt; worldi; ic++){
		for(int jc = 0; jc &lt;worldj; jc++){
			tmpArea = transWorld[ic][jc];
				for(int kc = 0; kc &lt; 4; kc++){
					tempCoord = tmpArea.coord[kc];
					tempNormal = tmpArea.normals[kc];
					tempCoord2 = tmpArea.coord[(kc+1)%4];
					tempNormal2 = tmpArea.normals[(kc+1)%4];
</code></pre>
<p>(...)</p>
<p>kommen total verwirrte Sachen raus!</p>
<p>Ich hab mir einen Breakpoint gesetzt und mir die Daten aus dem Debugger ausgelesen:<br />
Wenn ich mit der Maus über ic geh' - steht da &quot;ic = 10&quot;, wenn ich aber über jc geh' - steht da &quot;int jc&quot; !!!<br />
Als nächstes geh ich über tempCoord - da steht zB {123.4, 1.2, 12.3}<br />
im tempCoord2 steht das selbe!!!<br />
Und das beste ist: wenn ich mir angucke was im tempArea steht - ist alles auf 0.0 gesetzt!!!<br />
Da frag ich mich wie er dann auf die tempCoord Werte gekommen ist?!?! Wenn in der tmpArea nur 0.0 stehen?</p>
<p>Ich dahte das hätte was mit den call-by-value und call-by-refference zu tun, aber ich habe den Code nochaml umgeschrieben, damit es davon nicht abhängt - aber es geht weiter nicht...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1010662</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1010662</guid><dc:creator><![CDATA[am2pm]]></dc:creator><pubDate>Tue, 07 Mar 2006 17:36:52 GMT</pubDate></item><item><title><![CDATA[Reply to [C++] struct in zweidimensionalem Array on Tue, 07 Mar 2006 18:58:33 GMT]]></title><description><![CDATA[<p>einen Fehler hab ich schon gefunden und behoben - nähmlich:<br />
transArea-&gt;coord[k] = rotateVector((tmpArea-&gt;coord[k]), 360.0f - yrot, 1);<br />
transArea-&gt;coord[k] = translateVector((tmpArea-&gt;coord[k]), -xpos, 0.0, -zpos);</p>
<p>die zweite Anweisung hat die Werte der ersten überschrieben.</p>
<p>Das Problem mit den komischen Zahlen besteht immer noch...<br />
Ich sehe nicht welche Anweisung mir die Daten auf Null stellen sollte.<br />
Translate und Rotate funktionieren auf jeden Fall richtig.<br />
Kann mir vlt. jemand sagen ob die Pointer richtig verwendet werden? Bin in diesem Thema noch nicht so richtig sicher.</p>
<p>EDIT: LÖÖÖÖÖÖL... hab den breakpoint ausserhalb der Schleife plaziert, wo tempArea initialsiert wird... &lt;blödman&gt; <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";)"
      alt="😉"
    /> <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f644.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--face_with_rolling_eyes"
      title=":rolling_eyes:"
      alt="🙄"
    /></p>
<p>Collision funtzt zwar weiter nicht aber jetzt seh' ich auch die Daten zum debuggen <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";)"
      alt="😉"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1010781</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1010781</guid><dc:creator><![CDATA[am2pm]]></dc:creator><pubDate>Tue, 07 Mar 2006 18:58:33 GMT</pubDate></item></channel></rss>