# Questions about MDX/C# Engine ...

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

## Recommended Posts

So, I started development on my little engine in C#, using Managed DX 9. Right now, it can initialize a window, using windowed or fullscreen, render to specified control/form (passed in "engine.InitGraphics"), use textures, and load/display .X mesh files. But, I have a couple questions. First, is it okay/a good idea for my engine to wrap D3D functions, such as "BeginScene()", "Clear" "EndScene", etc.? Or should I just do "engine.GetDevice().BeginScene()" and so on? Second, I did this in DX 8 and VC++ 6. But I can't find the project anywhere. I don't know what happened to it. But how do I rotate the world around the player? I have a mesh class, and I thought it went something like this: Store current world matrix Set world matrix (in "MyMesh.Draw") to "Matrix.Identity" Translate, rotate, and scale to the user's values Render the mesh Call "device.Transform.World = oldWorldMatrix;" But when I do that, and I rotate the world matrix in the actual application, the mesh doesn't move at all. It stays in the exact same position on the screen. So if someone could re-enlighten me on how to rotate the world around the camera I would greatly appreciate it. Thanks in advance, Matt U.

##### Share on other sites
Okay, so it's been a while. I'm bumping my post. LoL.

But, I asked my question early in the morning, so I didn't expect it to last long.

But does anyone have any idea about my questions? Any help is appreciated! =)

##### Share on other sites
Good morning :)

Quote:
 But, I have a couple questions. First, is it okay/a good idea for my engine to wrap D3D functions, such as "BeginScene()", "Clear" "EndScene", etc.? Or should I just do "engine.GetDevice().BeginScene()" and so on?

It depends completely on what you need. If you're setting up an engine that will only render to one render target during a frame, you might just as well wrap this into the engine to save yourself some typing. When you're rendering to another target (to a texture for reflection for example), you might want to call these methods yourself to make sure they're called when they're supposed to be called.

For my own engine, I've wrapped these methods in my base Scene class's virtual Render method rather than in my Engine class. This allows me to just call Scene.Render(device) for basic scenes and optionally override the Render method for Scene subclasses that need custom handling.

Quote:
 Second, I did this in DX 8 and VC++ 6. But I can't find the project anywhere. I don't know what happened to it. But how do I rotate the world around the player? I have a mesh class, and I thought it went something like this:Store current world matrixSet world matrix (in "MyMesh.Draw") to "Matrix.Identity"Translate, rotate, and scale to the user's valuesRender the meshCall "device.Transform.World = oldWorldMatrix;"

If you're applying those transformations on the device.Transform.World matrix directly, then it should indeed do nothing. When you retrieve this matrix to change it, you will be given a copy of the matrix to operate on, since it's a value type (more info here). You typically will want to create the matrix first and only then set it as the device's world transform, like this:

Matrix world = Matrix.Scale(0.5f, 0, 0) * Matrix.Translate(10f, 0, 0); // etcdevice.Transform.World = world;

Quote:
 So if someone could re-enlighten me on how to rotate the world around the camera I would greatly appreciate it.

Wouldn't it be easier just to rotate the camera to look in the right direction, instead of rotating the world around it? You could use the following code to rotate the camera around the y-axis:

Vector3 lookAt = new Vector3(1,0,0);Vector3 up = new Vector3(0,1,0);Matrix matYaw = Matrix.RotationAxis(up, someRotationAngle); // your angle goes herelookAt = Vector3.TransformCoordinate(lookAt, matYaw);Vector3 cameraPosition = new Vector3(10, 0, 10); // some vector3 where you cam is atVector3 target = cameraPosition + lookAt;device.Tranform.View = Matrix.LookAtLH(cameraPosition, target, up);

Undoubtedly this can be done easier, but this works for me :) For more info on camera's, check out ToyMaker's excellent page on the subject.

##### Share on other sites
Thanks a lot. =) I didn't have time to check back earlier today. But we had a small line of storms moving through, with a lot of lightning. =P

Well, it's really early in the morning here (2:50AM). But I'll get back to MY computer later on. And I'll try your suggestions. Thanks again. =)