🔒 Locked
basic scene
Advertisement
Original Post
well it's not a problem but it get's me somesort confused. C# and managed dx. How can I render: 1 background 2 objects 3 particles I am intending to use quads to draw them , how can I change their position at the runtime and draw them efficiently? I know how to create and draw indexed + vertex buffer, but moving objects and drawing them separately is still a secret. tnx in advance.
Take a look at using Sprite. It should allow you to efficently draw moving textures if that is what you are trying to do. Are you shooting for 2D or 3D?
Outside of Sprite you typically move/position objexts by changing the World transformation (Device.Transform.World) to a matrix that represents the transformation that you want. Do this before every call to DrawPrimitive. Take a look at the Matrix struct, it contains a number of methods to aid you in creating a transformation matrix.
hope this helps.
Outside of Sprite you typically move/position objexts by changing the World transformation (Device.Transform.World) to a matrix that represents the transformation that you want. Do this before every call to DrawPrimitive. Take a look at the Matrix struct, it contains a number of methods to aid you in creating a transformation matrix.
hope this helps.
yep sprite is good thing to do, but not the best . I am just wondering how moving objects aremade in directx, this vertex buffer and index buffer confuse me. In opengl for example I can draw 3d object anywhere I like then change to next position and draw another object. But here is different.
nope it's not bad :). I am just pointing out that Nvidia grpahical cards have a big speed decrease as I understood. Well here is the idea I came up with, but I can't get it done right.
for example i have already created vertex&index buffer (m_aVertices and m_aIndices) with a quad in it.
now I draw it
then I wan't to draw the same quad at other location
I use this :
Now I draw it again:
And now I change camera position :
The position changing is ok. But somehow only the first quad is rotated. :(
What I wanted to do is draw each object on the scene , then use camera to show the scene at some location.
for example i have already created vertex&index buffer (m_aVertices and m_aIndices) with a quad in it.
now I draw it
Quote:
device.DrawIndexedPrimitives(Direct3D.PrimitiveType.TriangleList,
0,
0,
m_aVertices.Length,
0,
m_aIndices.Length / 3);
then I wan't to draw the same quad at other location
I use this :
Quote:
device.Transform.World = Matrix.Translation(2.0f,0.0f,0.0f);
Now I draw it again:
Quote:
device.DrawIndexedPrimitives(Direct3D.PrimitiveType.TriangleList,
0,
0,
m_aVertices.Length,
0,
m_aIndices.Length / 3);
And now I change camera position :
Quote:
Microsoft.DirectX.Vector3 cameraPosition = new Vector3(0.0f,1.2f,-2.0f);
Microsoft.DirectX.Vector3 cameraTarget = new Vector3(0.0f,0.0f,0.0f);
Microsoft.DirectX.Vector3 cameraUpVector = new Vector3(0.0f, 1.0f, 0.0f);
device.Transform.View = Matrix.LookAtLH(cameraPosition, cameraTarget, cameraUpVector);
device.Transform.Projection = Matrix.PerspectiveFovLH((float)System.Math.PI/4, 4.0f / 3.0f, 1.0f, 100.0f);
The position changing is ok. But somehow only the first quad is rotated. :(
What I wanted to do is draw each object on the scene , then use camera to show the scene at some location.
Quote:
Original post by DMINATOR
"If you're thinking about using DrawPrimitiveUP, consult a doctor. It's as bad as that."
Not exactly.
Quote:
Original post by Coder Quote:
Original post by DMINATOR
"If you're thinking about using DrawPrimitiveUP, consult a doctor. It's as bad as that."
Not exactly.
OK this make things clearer.
I am also trying an alternative way. By using sprites, I finally managed to draw a sprite and rotate it :)
Here is the code if any one needs it
sprite rotation :
This code would be helpfull when trying to draw things like compass in 2d hud. But what to do if I want to draw sprites in world coordinates ? How can I set up matrix ?
Here is the code if any one needs it
sprite rotation :
//starting sprite drawing sequence sprite.Begin(Direct3D.SpriteFlags.None); //let's create matrix with center point in the center of form //and rotation center - half image size which is 64x64 = 32pixels Matrix tr= Matrix.AffineTransformation2D( 1.0f, new Vector2(32,32), System.Environment.TickCount / 500.0f ,new Vector2(this.Width / 2,this.Height / 2));//Matrix.Translation(32.0f,32.0f,0.0f); //here we assign this matrix to our sprite sprite.Transform = tr; //now let's draw it sprite.Draw(texture,System.Drawing.Rectangle.Empty, new Vector3(0.0f,0.0f,0.0f),new Vector3(0.0f,0.0f,0.0f),System.Drawing.Color.FromArgb(0,100,255,100)); //end of sprite drawing sequence sprite.End();This code would be helpfull when trying to draw things like compass in 2d hud. But what to do if I want to draw sprites in world coordinates ? How can I set up matrix ?
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement