Sign in to follow this  

Newbie Question, Transformations Help (not the usual)

This topic is 4661 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 am reasonably new to DirectX (I can do transforms, texturing etc) but I have a question on exactly what the World Transform effects. I know basically what it does, you set up your objects in their own model space and then you position them in the scene with a world matrix transform and each world transform is usually different for each object (unless they are in the same position with same rotation and scaling). My question is more to do with which values are affected. I have a cube and I want to setup a hemicube over each vertex (I have the hemicube working with the interception methods etc) so when I pass it a point I can work out the ray (centre of hemicube - ray origin, its for one of my projects where a ray is always defined as that) and work out where the hemicube intercepts. The question I have however is when I load up my objects they are defined in model space. I need them to be in world space to be able to work out the ray correctly. So I was wondering, what is the best way of working this out? In all of the Transform tutorials I have seen they always set the transform Device->SetTransform(D3DTS_WORLD, &proj) and then draw their object, set another world transform and render another object.. So my confusion is how would I find out the world positons of my objects after these transforms? Would I set up my vertex buffer including all positions of the hemicubes etc and then is there a method to transform the vertex buffer and read the world coordinates back? Or is it better to keep a copy of the coordinates and apply another world transform of my own to the points, find out intersections set colours and then let DirectX apply the same transforms when rendering using Device->SetTransform(D3DTS_WORLD, &proj)? If so then I would be transforming my coordinates twice, once for my local copy and once for rendering. So basically I start my program, define my cube setup hemicubes over each vertex, setup some other objects. Then I want to transform then to the world, go through each vertex on my cube and work out rays from that vertex to the other objects and find where they intersect my hemicube. The only problem I have is I don't know how I would go about finding out the coordinates of my objects after the world transform. This definately has a super easy answer but the tutorials and books I have looked at don't seem to cover this. I think you can probably tell that I'm confused with whats going on here. If anyone needs me to explain it again I would be happy to try my best. Thanks for the help, this seems like an amazing site!

Share this post


Link to post
Share on other sites
If you already have it setup so that your hemicubes are on the corners of your cubes or wherever you want them to be then you do not need to worry about doing the world transform.... DirectX automatically does a default world transform and transforms your object to the origin. So if you just let DirectX do the world transform then to find the coordinates of your box's corners you just need to know the size of the box.... which depending on where the box came from could be easy. If you made the cube by a call to D3DXCreateBox or if you just made it by hand then you should know the coords of all the corner vertices in object space and when it gets transformed to the origin these coordinates will be exactly the same provided you do not perform any other transformations on your box.

If you don't have it so your hemicubes are already on the corners of the box... once again just let DirectX do the world transform for your box (ie don't call device->SetTransform(D3DTS_WORLD, blah) until after you have called box->DrawSubset. THEN you need to transform each of your boxes to the corners of the box which you do by:

1. Creating a vector that has the coords of the box corner (you should know it for same reasons as above).
2. Creating a transformation matrix from this vector by calling D3DXMatrixTranslation(aMatrix, vector.x, vector.y, vector.z)
3. Setting the world transform with this matrix
ie. device->SetTransform(D3DTS_WORLD, aMatrix)
4. Rendering the hemicube.

Do these steps for each hemicube (using a different vector for each corner obviously) and everything should be cool.

Hope this helps

Share this post


Link to post
Share on other sites
Hi,

Thanks for the reply, however, I don't think I explained my problem adequately. I'll give an example:

* I have a cube, it is defined in model space
* I create hemicubes at each vertex of the cube
* I apply a world transform to the cube (and hemicubes at each vertex)
* Apply a world transform to each of the other objects I am rendering so that everything is in world space

Now, I can do the stages above, its the following stage I have trouble with:

* After everything is in world space, for each hemicube on the cube I go through each object in world space and find the ray to the centre of my hemicube.

I'm not sure how to do that part, I will need the positions of all vertices in worldspace. I'm not sure where to get that information.

Thanks

Share this post


Link to post
Share on other sites

This topic is 4661 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this