Note that there are some explanatory texts on larger screens.

plurals
  1. POXNA - Render Tree rotations and translations
    primarykey
    data
    text
    <p>I have started working with XNA this week, currently building a good core that I will be able to use for future games.</p> <p>I can't complete my render tree because I don't know how to code the following:</p> <p>(I am used to work with OpenGL a lot, so I am looking for the fastest equivalent to this code)</p> <pre><code>public void DrawRecursively( GameTime deltaTime ) { glPushMatrix(); /* these 3 lines are what i didn't figure out with XNA */ glTranslate3f( position[0], position[1], position[2] ); glRotatef( theta, 0.0f, 1.0f, 0.0f ); glRotatef( phi, 1.0f, 0.0f, 0.0f ); this.Draw( deltaTime ); foreach ( ComponentInterface child in childs ) { child.DrawRecursively( deltaTime ); } glPopMatrix(); } </code></pre> <p>My current attempt is something like this:</p> <pre><code>public void DrawRecursively( GameTime deltaTime, Matrix worldMatrix ) { Matrix backup = worldMatrix; // TRANSLATE HERE. // ROTATE HERE. this.Draw( deltaTime ); foreach ( ComponentInterface child in childs ) { child.DrawRecursively( deltaTime, worldMatrix ); } worldMatrix = backup; } </code></pre> <p>I understand that the worldMatrix can't be implicitly accessed from anywhere and that you have to carry a reference to it. How do I translate and rotate then? And is my <code>worldMatrix</code> backup the correct way to do the equivalent of a <code>glPushMatrix</code>/<code>PopMatrix</code> block?</p> <p>Thanks,</p> <p>Nick</p> <hr> <p>EDIT:</p> <p>I think I managed to make a few steps forward, this being said, it is still not working. God I miss openGL and all the detailed documentation, MSDN won't give me much info... Here is my latest approach :</p> <pre><code>public void DrawRecursively( GameTime deltaTime, BasicEffect effect ) { Matrix worldMatrix = effect.World; Matrix backup = worldMatrix; worldMatrix = worldMatrix * Matrix.CreateTranslation( position.ToVector3() ); worldMatrix = worldMatrix * Matrix.CreateRotationY( theta ); worldMatrix = worldMatrix * Matrix.CreateRotationX( phi ); effect.Parameters["xWorld"].SetValue( worldMatrix ); this.Draw( deltaTime ); foreach ( ComponentInterface child in childs ) { child.DrawRecursively( deltaTime, effect ); } effect.Parameters["xWorld"].SetValue( backup ); } </code></pre> <p><code>effect.Parameters["xWorld"]</code> returns me a null pointer so <code>SetValue</code> obviously throws me an access violation error. I have double checked and the effect instance is correctly initialize, according to the debugger. </p> <p>Is this the correct way to do it?</p> <hr> <p>EDIT AGAIN :</p> <p>Thanks to your help, I am a little close to success, but the triangle is still static and wont rotate even when incrementing its orientation angles.</p> <pre><code>public void DrawRecursively( GameTime deltaTime, BasicEffect effect ) { Matrix worldMatrix = effect.World; Matrix backup = worldMatrix; effect.World = worldMatrix * Matrix.CreateScale( scale ) * Matrix.CreateRotationX( orientation.X ) * Matrix.CreateRotationX( orientation.Y ) * Matrix.CreateRotationX( orientation.Z ) * Matrix.CreateTranslation( position.ToVector3() ); this.Draw( deltaTime ); foreach ( ComponentInterface child in childs ) { child.DrawRecursively( deltaTime, effect ); } effect.World = backup; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload