Does managed DirectX provide a generic way to do this?
The device.Trans.Projection property provide a way to clip any
object, but the clipping planes (i.e the front and back clipping
of the frustum) have fixed angle. I need a clipping plane that
can be rotated in 3D space.
Thanks in advance.
James X. Li
For the first one see:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/directx9_m/directx/ref/ns/microsoft.directx.direct3d/c/renderstatemanager/p/clipping.asp?frame=true
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/directx9_m/directx/ref/ns/microsoft.directx.direct3d/s/clipstatus/clipstatus.asp?frame=true
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/directx9_m/directx/ref/ns/microsoft.directx.direct3d/e/clipstatusflags/clipstatusflags.asp?frame=true
There are 6 appliction defined clipping planes.
I've never used this but it seems like its what you want. The really odd
thing is that I can't find the API to actually set the user defined clipping
planes. I'm sure I'm just overlooking it and someone else will chime in.
For the second one, nothing in DirectX - do some searches for CSG
operations - there are probbly some libraries out there that can help.
--
Zman (mailto:zm...@thezbuffer.com)
http://www.thezbuffer.com
News and Resources for Managed DirectX
"James X. Li" <donot...@abc.net> wrote in message
news:O3z7ElZq...@TK2MSFTNGP15.phx.gbl...
Is there a way to call the unmanaged code from the managed code?
James
Oh and I've never seen code with this used so I would love to see an example
if you get it working - drop me an email I'll put it up on The ZBuffer, or
link to your blog.
--
Zman (mailto:zm...@thezbuffer.com)
http://www.thezbuffer.com
News and Resources for Managed DirectX
"James X. Li" <donot...@abc.net> wrote in message
news:eLeAEFeq...@TK2MSFTNGP09.phx.gbl...
---------- Cut Here -----------
using System;
using System.Drawing;
using System.ComponentModel;
using System.Windows.Forms;
using Microsoft.DirectX;
using Microsoft.DirectX.Direct3D;
using System.Threading;
namespace MeshClip {
public class MeshClip : System.Windows.Forms.Form {
private System.ComponentModel.Container components = null;
private Device device;
private float angle = 0;
private static bool stopFlag = false;
private Manifold manifold;
public MeshClip() {
InitializeComponent();
}
protected override void Dispose( bool disposing ) {
if( disposing ) {
if (components != null) {
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
private void InitializeComponent() {
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(592, 494);
this.Name = "Form1";
this.Text = "Form1";
this.KeyPress += new
System.Windows.Forms.KeyPressEventHandler(this.Form1_KeyPress);
}
#endregion
[STAThread]
static void Main() {
MeshClip frm = new MeshClip();
frm.InitializeGraphics();
frm.Show();
while (frm.Created) {
if ( ! stopFlag ) {
frm.Render();
}
Application.DoEvents();
Thread.Sleep(25);
}
frm.DisposeGraphics();
}
public void InitializeGraphics() {
PresentParameters pp = new PresentParameters();
pp.Windowed = true;
pp.BackBufferFormat = Format.X8R8G8B8;
pp.SwapEffect = SwapEffect.Discard;
pp.AutoDepthStencilFormat = DepthFormat.D16;
pp.EnableAutoDepthStencil = true;
device = new
Device(0,DeviceType.Hardware,this,CreateFlags.SoftwareVertexProcessing,pp);
device.RenderState.Lighting = true;
device.RenderState.Ambient = Color.Gray;
device.Lights[0].Type = LightType.Directional;
device.Lights[0].Direction = new Vector3(2, 2, -4);
device.Lights[0].Diffuse = Color.FromArgb(0xff, 0xcc, 0x99);
device.Lights[0].Enabled = true;
device.Lights[1].Type = LightType.Directional;
device.Lights[1].Direction = new Vector3(-1, -1, 4);
device.Lights[1].Enabled = true;
device.RenderState.Lighting = true;
device.RenderState.CullMode = Cull.None;
device.Transform.Projection =
Matrix.PerspectiveFovLH((float)Math.PI / 4, this.Width / this.Height,0.2f,
10);
manifold = new Torus(device);
}
public void DisposeGraphics() {
device.Dispose();
}
public void Render() {
device.Clear(ClearFlags.Target |
ClearFlags.ZBuffer,Color.CornflowerBlue ,1,0);
device.Transform.View = Matrix.LookAtLH(new Vector3(0,0,-5),new
Vector3(0,0,0),new Vector3(0,1,0));
device.Transform.World =
Matrix.Multiply(Matrix.RotationY(Geometry.DegreeToRadian(angle)),Matrix.RotationX
(Geometry.DegreeToRadian(angle)));
device.Transform.World =
Matrix.Multiply(device.Transform.World,Matrix.RotationZ(Geometry.DegreeToRadian(-angle)));
device.BeginScene();
manifold.Render(device);
angle += 2.0f;
if (angle == 360.0f) {
angle = 0;
}
device.EndScene();
device.Present();
}
private void Form1_KeyPress(object sender,
System.Windows.Forms.KeyPressEventArgs e) {
if (e.KeyChar.ToString() == "w") {
if (device.RenderState.FillMode == FillMode.WireFrame) {
device.RenderState.FillMode = FillMode.Solid;
device.RenderState.CullMode = Cull.CounterClockwise;
}
else {
device.RenderState.FillMode = FillMode.WireFrame;
device.RenderState.CullMode = Cull.None;
}
} else if (e.KeyChar.ToString() == "s") {
stopFlag = !stopFlag;
} else if (e.KeyChar.ToString() == "q") {
this.Close();
}
}
}
interface Manifold {
void Render(Device dev);
}
class Torus : Manifold {
Mesh mesh;
Material material;
public Torus(Device dev) {
mesh = Mesh.Torus(dev, 0.5f, 1.0f, 100, 100);
material = new Material();
material.Diffuse = Color.Gray;
}
public void Render(Device dev) {
dev.Material = material;
// Clip out half of the torus.
ClipPlane plane0 = dev.ClipPlanes[0] as ClipPlane;
plane0.Enabled = true;
Vector4 v = new Vector4(1.0f, 0.0f, 0.0f, 0.0f);
v.Transform(dev.Transform.World);
plane0.SetSingleArray(new float[]{v.X, v.Y, v.Z, v.W});
mesh.DrawSubset(0);
}
}
}