How to construct a surface in VC# with the help of DirectX?

  • Thread starter Thread starter Zoury
  • Start date Start date
I have not understood your answer. Explain, please, your answer more in
detail.

Dr. Zharkov V.A., Moscow, Russia.
 
You need to
1. Set up a device

internal void initGraphics()
{
// Set our presentation parameters, set up the Direct3D device
presentParams = new PresentParameters();
presentParams.Windowed = true;
presentParams.SwapEffect = SwapEffect.Discard;
presentParams.DeviceWindow = this.portalPanel; //the subclass of Form you
are drawing on .

//set up z buffer so that near objects obscure far objects.
//If graphics card does not support we are in trouble here.
presentParams.EnableAutoDepthStencil = true;
presentParams.AutoDepthStencilFormat = DepthFormat.D16;
// Store the default adapter
int adapterOrdinal = Manager.Adapters.Default.Adapter;
CreateFlags flags = CreateFlags.SoftwareVertexProcessing;
Caps caps = Manager.GetDeviceCaps(adapterOrdinal, DeviceType.Hardware);
// Do we support hardware vertex processing?
if (caps.DeviceCaps.SupportsHardwareTransformAndLight)
// Replace the software vertex processing
flags = CreateFlags.HardwareVertexProcessing;
// Do we support a pure device?
if (caps.DeviceCaps.SupportsPureDevice)
flags |= CreateFlags.PureDevice;
flags = CreateFlags.HardwareVertexProcessing; //better be there...

try
{
// Create our device
device = new Device(adapterOrdinal, DeviceType.Hardware,
this.portalPanel, flags, presentParams);
}
catch
{
if (device != null)
device.Dispose();
MessageBox.Show("unable to create device");
clearFlags = ClearFlags.Target;
presentParams.EnableAutoDepthStencil = false;
presentParams.AutoDepthStencilFormat = DepthFormat.D16;
}
}

2. Set up a buffer that contains triangles whose vertices are on the
surface. If the triangles are small enough you get a reasonable
approximation to the surface. Alternatively, you can just render points on
the surface (but this will not give you lighting effects). You can render a
list of lines as well.


device.BetginScene();
device.DrawUserPrimitives(PrimitiveType.TriangleList, triangleCount,
renderBuffer);
device.EndScene();
device.Present();

where renderBuffer contains your list of triangles.

You also need code to set the position of the camera, the position of the
lights, and to set up matrices for transforming from object space to model
space to world coordinates. All in all in might be 30-40 lines of code.
Something like:

device.RenderState.Ambient = Color.DarkBlue;device.RenderState.CullMode =
Cull.CounterClockwise;

device.RenderState.Lighting = true;

device.Lights[0].Type = LightType.Directional;

device.Lights[0].Diffuse = Color.LightBlue;

device.Lights[0].Direction = new Vector3(0, 0, -1);

device.Lights[0].Commit();

device.Lights[0].Enabled = true;



device.Transform.World = worldTransform;

device.Transform.Projection =

Matrix.PerspectiveFovLH(camera.fieldOfView, camera.aspectRatio,

camera.nearPlane, camera.farPlane);

device.Transform.View =

Matrix.LookAtLH(camera.positionV, camera.targetPosition,

camera.up);


I recommend the book "Managed DirectX 9", byTom Miller which has many
examples. Reading the documentation for the above mentioned functions (in
the DirectX 9 SDK) will help as well.
 
Hello. I have installed on my computer Visual Studio 2005 Beta and DirectX
9.0 SDK Update - (Summer 2004). I have developed projects Visual C#, Visual
Basic and Visual C++ for construction of 3-Dimensional geometrical bodies,
surfaces and lines of a level of these surfaces without use of DirectX, and
now I want to make the same with use of DirectX.

Inform, please, where it is possible to find an example of construction of a
geometrical body or a surface z = f(x, y), for example, part of sphere on
Form1 in project Visual C# or Visual Basic, or Visual C++, Windows
Application

from Visual Studio of version (.NET) 2002 or (.NET) 2003, or 2004, or 2005

with the help of DirectX 9.0?

Beforehand many thanks for your answer.

Dr. Zharkov V.A., Moscow, Russia.
 
Dear Mr. Fred Mellender.

Many thanks for your answer.

In projects Visual C#, Windows Application (from Visual Studio 2005) on the
Form1 I have constructed all six examples from Tutorial 1-6 (DirectX 9.0 SDK
Update - Summer 2004, Direct3D). On the Form1 with the help of Tutorial 4 I
have constructed the rotating cylinder.

Inform, please, as it is necessary to change the program in Tutorial 4, that
instead of the cylinder the sphere rotated?

Beforehand many thanks for your answer.

Dr. Zharkov V.A., Moscow, Russia.
 
Back
Top