Jump to content
  • Advertisement
Sign in to follow this  
MrM

Transformation Problem

This topic is 4756 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi! I'm new to DX buit not to CG so i know how to use a Matrix but DX kills me.. :( here is what i try to do:
			m_Device.SetTexture(0,this.texture);
			m_Device.SetStreamSource(0, GraphicBuffer, 0);
			m_Device.VertexFormat=CustomVertex.TransformedTextured.Format;
			m_Device.Transform.World = Matrix.Translation(100.0f,0.0f,0.0f);
			m_Device.DrawPrimitives(PrimitiveType.TriangleStrip, 0, 2);
			m_Device.Transform.World = Matrix.Translation(-100.0f,0.0f,0.0f);
But nothing happens... The Object is drawn like before... ??? Anyone an idea why?

Share this post


Link to post
Share on other sites
Advertisement
hmm ... shouldn't there be a "SetIndices" somewhere ?
I don't know managed DirectX, but in C++, you make a SetStreamSource(), a SetIndices() and a DrawPrimitive(). If one of the 3 misses, it failes ^^

Edit : As said by Omid, it's only for indexed primitives, sorry I misread the intia
initial post ^^''

[Edited by - paic on October 7, 2005 8:44:07 AM]

Share this post


Link to post
Share on other sites
Hello,

paic, that is only when you are drawing indexed primitives =)

MrM,
Is that which you are showing all your code? In that case your problem here is that
you have to redraw your scene!
D3D works like this:
You set the device ( texture, matrices, e.t.c )
Then you draw

Any changes to the device after drawing will NOT affect what you have already drawn.

Since I don't know your goal, I can't help you more than to just point out the error!
But if you still have problems, let us know what you are trying to do, and we will gladly help you with a solution =)

Hope this helps!

Regards,
/Omid

Share this post


Link to post
Share on other sites
Sorry!

For shure there is more code but it is elsewhere...

these 4 lines are executed in another object.

the device this points to is already set to

device.BeginScene();

and after the code i do

device.EndScene();
device.Present();

hmm.. donؤT think there is something missing?
because the Polygons are drawn.. but the transformation takes no effect..
here is how i set my vertices: (just a Quad with a texture)


texture = new Texture(m_Device, bitmap, 0, Pool.Managed);

CustomVertex.TransformedTextured[] verts = new CustomVertex.TransformedTextured[4];
GraphicBuffer = new VertexBuffer(typeof(CustomVertex.TransformedTextured), 4, m_Device, Usage.WriteOnly, CustomVertex.TransformedTextured.Format, Pool.Default);

verts = (CustomVertex.TransformedTextured[])GraphicBuffer.Lock(0, LockFlags.None);
verts[0] = new CustomVertex.TransformedTextured(m_x, m_y, 1, 1, 0, 0); // Top Left
verts[1] = new CustomVertex.TransformedTextured(m_x + m_witdh, m_y, 1, 1, 1, 0); // Top Right
verts[2] = new CustomVertex.TransformedTextured(m_x, m_y + m_height, 1, 1, 0, 1); // Bottom Left
verts[3] = new CustomVertex.TransformedTextured(m_x + m_witdh, m_y + m_height, 1, 1, 1, 1); // Bottom Right
GraphicBuffer.Unlock();



[Edited by - Coder on October 7, 2005 8:59:33 AM]

Share this post


Link to post
Share on other sites
I'm not 100% sure, but I don't think the TransformedTextured vertices use the world matrix at all. The TranformedTextured vertices are already in screen coordinates, so DX won't apply any matrix transformations to them. If you want to use the world matrix, use the PositionTextured type vertices instead.

However, this means you'll have to set up your camera properly, but as you're already locking the vertexbuffer to manipulate the vertices that shouldn't pose a problem I guess :)

Share this post


Link to post
Share on other sites
hmm... now the Polygon are gone...
Don't know why.. really strange...
Here is the new code:

Vertex init:


CustomVertex.PositionTextured[] verts = new CustomVertex.PositionTextured[4];
GraphicBuffer = new VertexBuffer(typeof(CustomVertex.PositionTextured), 4, m_Device, Usage.WriteOnly, CustomVertex.PositionTextured.Format, Pool.Default);
verts = (CustomVertex.PositionTextured[])GraphicBuffer.Lock(0, LockFlags.None);
verts[0] = new CustomVertex.PositionTextured(m_x, m_y, 1, 0, 0); // Top Left
verts[1] = new CustomVertex.PositionTextured(m_x + m_witdh, m_y, 1, 1, 0); // Top Right
verts[2] = new CustomVertex.PositionTextured(m_x, m_y + m_height, 1, 0, 1); // Bottom Left
verts[3] = new CustomVertex.PositionTextured(m_x + m_witdh, m_y + m_height, 1, 1, 1); // Bottom Right
GraphicBuffer.Unlock();


Drawing:

m_Device.VertexFormat=CustomVertex.PositionTextured.Format;
m_Device.SetStreamSource(0, GraphicBuffer, 0);
m_Device.DrawPrimitives(PrimitiveType.TriangleStrip, 0, 2);


And the Camera:

float width = (float)_targetControl.Size.Width;
float height = (float)_targetControl.Size.Height;
float centerX = width / 2.0f;
float centerY = height / 2.0f;
Vector3 cameraPosition = new Vector3(centerX, centerY, -5.0f);
Vector3 cameraTarget = new Vector3(centerX, centerY, 0.0f);


m_Device.Transform.View = Matrix.LookAtLH(cameraPosition, cameraTarget,
new Vector3(0.0f, 1.0f, 0.0f));
m_Device.Transform.Projection = Matrix.OrthoLH(width, height, 1.0f, 10.0f);

Share this post


Link to post
Share on other sites
I don't have any experience with orthogonal (sp?) projection matrices, but all MDX code I've seen so far typically uses Matrix.PerspectiveFOVLH as the projection matrix, like this:


// fov, aspect ratio, near plane, far plane
device.Transform.Projection = Matrix.PerspectiveFovLH( (float)Math.PI / 4.0f, ((float)width) / ((float)height), 0.1f, 100.0f);


I don't know if you picked the ortho projection with a reason (in fact, I haven't got a clue what it does :), but if you simply want to display that quad of yours PerspectiveFOVLH should do just fine. The only other things I can think of is that your xyz vertex coords are out of the camera view, or that you don't set your texture in your new code.

EDITED:

Aside from the orthogonal matrix, I just saw your still using screen space coordinates to set up your camera position and targets. This is proably causing your problem, since your camera is most likely positioned to the right of your quad (provided you haven't applied any world transforms on it and you used world space coordinates for the vertices), happily looking at the empty space next to your quad.

Try setting up both your camera position and targets in world space and make sure your vertex coordinates are in world space too. If your goal is to simply draw a number of quads (for sprites for example), you might be better off with multiple quads with the TransformedTextured, or even better yet by using the MDX Sprite class.

Hope this helps!

Share this post


Link to post
Share on other sites
You need ortho if you don't want a perspective change in legths..
I need this because it will get a 2Dimensional Game.. ;)
I don't think this will cause a problem in Rendering or?

Share this post


Link to post
Share on other sites
They aren't rendering because they're being clipped. Your far plane is set to 10.0f (the 4th argument of the Ortho matrix call) and the vertices get transformed to 100.0f. So they're clipped.

Either make your far plane further, or bring the geometry closer.

Share this post


Link to post
Share on other sites
Sorry my edit took so long :) Check my reply for the reason, but if your making a 2D game, I'd go with the MDX Sprites. That'll allow you to draw textures onto a predefined quad without any 3D things to worry about.

The only downside is that you obiously won't be able to perform any typical 3D things, like intersection tests etc. For occlusion (for lack of a better word, drawing something on top of something else :) you could sort the textures you want to draw before rendering, or you could use multiple sprites as layers.

Edited yet again:

Come to think of it, you also won't be able to perform world transformations all over again, what started this discussion... If you are really sure you want the world transforms, you'll have to work out your world coordinates first.... And yes, it might even be that simple clipping problem ;)

Hope this does help :D

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!