<?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[Vektor Klasse in float[]]]></title><description><![CDATA[<p>Hi,</p>
<p>ich habe eine Klasse zur Verwaltung von 3D Vektoren:</p>
<pre><code class="language-cpp">class Vektor
{
    float x,y,z;

...
}
</code></pre>
<p>ich habe es bereits geschaft ein float arry der Länge 3 in solch einen Vektor zu konvertieren:</p>
<pre><code class="language-cpp">Vektor v;  
float  arry[3]; //natürlich auch initialisiert
v = *(VECTOR_3F*) arry;
</code></pre>
<p>Aber wie geht das andersherum? Wie konvertiere ich solch einen Vektor in ein float arry?</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/266999/vektor-klasse-in-float</link><generator>RSS for Node</generator><lastBuildDate>Wed, 02 Sep 2026 19:00:15 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/266999.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 17 May 2010 18:56:53 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Vektor Klasse in float[] on Mon, 17 May 2010 18:56:53 GMT]]></title><description><![CDATA[<p>Hi,</p>
<p>ich habe eine Klasse zur Verwaltung von 3D Vektoren:</p>
<pre><code class="language-cpp">class Vektor
{
    float x,y,z;

...
}
</code></pre>
<p>ich habe es bereits geschaft ein float arry der Länge 3 in solch einen Vektor zu konvertieren:</p>
<pre><code class="language-cpp">Vektor v;  
float  arry[3]; //natürlich auch initialisiert
v = *(VECTOR_3F*) arry;
</code></pre>
<p>Aber wie geht das andersherum? Wie konvertiere ich solch einen Vektor in ein float arry?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1898619</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1898619</guid><dc:creator><![CDATA[Mike789]]></dc:creator><pubDate>Mon, 17 May 2010 18:56:53 GMT</pubDate></item><item><title><![CDATA[Reply to Vektor Klasse in float[] on Mon, 17 May 2010 18:59:57 GMT]]></title><description><![CDATA[<p>Gar nicht, denn es geht nicht. Nutze lieber std::vector oder boost::array. Obwohl die zwei Templates für diesen Kleinkram wohl overkill sind.</p>
<p>Alternative: Alle Elemente einzeln zuweisen</p>
<pre><code class="language-cpp">float arr[3];
arr[0] = ptr[0];
arr[1] = ptr[1];
arr[2] = ptr[2];
</code></pre>
<p>Oder eben mit Funktionen wie memcpy die Bytes kopieren.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1898623</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1898623</guid><dc:creator><![CDATA[Janjan]]></dc:creator><pubDate>Mon, 17 May 2010 18:59:57 GMT</pubDate></item><item><title><![CDATA[Reply to Vektor Klasse in float[] on Mon, 17 May 2010 19:03:55 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">Vektor v;
float arr[3]; 
arr[0] = v.x; 
arr[1] = v.y; 
arr[2] = v.z;
</code></pre>
<p>So mache ich das zur Zeit.<br />
Ich hatte aber gehofft, dass das schneller geht.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1898628</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1898628</guid><dc:creator><![CDATA[Mike789]]></dc:creator><pubDate>Mon, 17 May 2010 19:03:55 GMT</pubDate></item><item><title><![CDATA[Reply to Vektor Klasse in float[] on Mon, 17 May 2010 19:13:35 GMT]]></title><description><![CDATA[<p>Wie wäre es mit einem Konstruktor?</p>
<pre><code class="language-cpp">Vektor(const float *arr)
{
	x = arr[0];
	//...
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1898634</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1898634</guid><dc:creator><![CDATA[TyRoXx]]></dc:creator><pubDate>Mon, 17 May 2010 19:13:35 GMT</pubDate></item><item><title><![CDATA[Reply to Vektor Klasse in float[] on Mon, 17 May 2010 19:18:08 GMT]]></title><description><![CDATA[<p>Mike789 schrieb:</p>
<blockquote>
<pre><code class="language-cpp">Vektor v;
float arr[3]; 
arr[0] = v.x; 
arr[1] = v.y; 
arr[2] = v.z;
</code></pre>
<p>So mache ich das zur Zeit.<br />
Ich hatte aber gehofft, dass das schneller geht.</p>
</blockquote>
<p>Warum definierst Du &quot;Vektor&quot; nicht einfach mit einem float[3] als Datenelement? Dann darfst Du auch std::memcpy verwenden, um die Elemente zu kopieren und kannst auf x/y/z per Index zugreifen. Und wenn Dir v.coeffs[idx] zu umständlich ist, kannst Du ja den operator[] überladen. Und wenn Du die Elemente noch benennen willst, kannst Du ja entsprechende Zugriffsfunktionen definieren -- v.x() könnte eine Referenz auf das richtige Element liefern.</p>
<p>kk</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1898640</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1898640</guid><dc:creator><![CDATA[krümelkacker]]></dc:creator><pubDate>Mon, 17 May 2010 19:18:08 GMT</pubDate></item><item><title><![CDATA[Reply to Vektor Klasse in float[] on Mon, 17 May 2010 19:57:29 GMT]]></title><description><![CDATA[<p>krümelkacker schrieb:</p>
<blockquote>
<p>Mike789 schrieb:</p>
<blockquote>
<pre><code class="language-cpp">Vektor v;
float arr[3]; 
arr[0] = v.x; 
arr[1] = v.y; 
arr[2] = v.z;
</code></pre>
<p>So mache ich das zur Zeit.<br />
Ich hatte aber gehofft, dass das schneller geht.</p>
</blockquote>
<p>Warum definierst Du &quot;Vektor&quot; nicht einfach mit einem float[3] als Datenelement? Dann darfst Du auch std::memcpy verwenden, um die Elemente zu kopieren und kannst auf x/y/z per Index zugreifen. Und wenn Dir v.coeffs[idx] zu umständlich ist, kannst Du ja den operator[] überladen. Und wenn Du die Elemente noch benennen willst, kannst Du ja entsprechende Zugriffsfunktionen definieren -- v.x() könnte eine Referenz auf das richtige Element liefern.</p>
<p>kk</p>
</blockquote>
<p>gute Idee!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1898659</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1898659</guid><dc:creator><![CDATA[Mike789]]></dc:creator><pubDate>Mon, 17 May 2010 19:57:29 GMT</pubDate></item></channel></rss>