Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

nickwinters

Stuff not appearing in order

This topic is 5330 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

Why would objects that are farther away appear in front of stuff that's closer? As you get closer, you'll go through the stuff that's closer, but it still shows the stuff that's farther away as in front of it. How do I fix this? Thanks. -Nick Edit: If possible, some code in MDX would be very useful. [edited by - nickwinters on April 12, 2004 10:15:18 AM]

Share this post


Link to post
Share on other sites
Advertisement
You have to make sure that you''ve set the appropriate D3DPRESENTPARAMS members to the correct values when you create your device.

Using models has nothing to do with the problem. Even if you use .x files, underneath, everything is still being rendered using index and vertex buffers.

neneboricua

Share this post


Link to post
Share on other sites
As far as the Z-buffer is concerned, the only ones you have to worry about are EnableAutoDepthStencil = TRUE and AutoDepthStencilFormat = D3DFMT_D16

neneboricua

Share this post


Link to post
Share on other sites
Out of desperation, I''m posting my code...

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using Microsoft.DirectX;
using Microsoft.DirectX.Direct3D;
using Nova.Tools;
using Nova.World;
using Nova.Input;

namespace Nova
{
///
/// Summary description for Form1.
///

public class Form1 : System.Windows.Forms.Form
{
private Device device = null;
private Mesh mesh = null;
private Material[] meshMaterials;
private Texture[] meshTextures;
private Course world;
private InputController ic;
private long ticksPerSecond=TimeSpan.TicksPerSecond;
private long TICKS_PER_GAMESTEP;
private DateTime previousTime=DateTime.Now;
private long passedTime=0;
private float angle = (float)Math.PI / (4f);
private float nearZ=0f;
private float farZ=1000.0f;


///
/// Required designer variable.
///

private System.ComponentModel.Container components = null;


public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
TICKS_PER_GAMESTEP=25*ticksPerSecond/1000;

this.SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.Opaque, true);
}

///
/// We will initialize our graphics device here
///

public void InitializeGraphics()
{
// Set our presentation parameters
PresentParameters presentParams = new PresentParameters();

presentParams.Windowed = true;
presentParams.SwapEffect = SwapEffect.Discard;
presentParams.EnableAutoDepthStencil = true;
presentParams.AutoDepthStencilFormat = DepthFormat.D16;


// Create our device
device = new Device(0, DeviceType.Hardware, this, CreateFlags.HardwareVertexProcessing, presentParams);
MeshStorage.setDevice(device);
world=new Course(device, nearZ, farZ);
ic=new InputController(this, world);
// Load our mesh
//LoadMesh(@".\tiny.x");
}

private void LoadMesh(string file)
{
ExtendedMaterial[] mtrl;

// Load our mesh
mesh = Mesh.FromFile(file, MeshFlags.Managed, device, out mtrl);

// If we have any materials, store them
if ((mtrl != null) && (mtrl.Length > 0))
{
meshMaterials = new Material[mtrl.Length];
meshTextures = new Texture[mtrl.Length];

// Store each material and texture
for (int i = 0; i < mtrl.Length; i++)
{
meshMaterials = mtrl[i].Material3D;
if ((mtrl[i].TextureFilename != null) && (mtrl[i].TextureFilename != string.Empty))
{
// We have a texture, try to load it
meshTextures[i] = TextureLoader.FromFile(device, @".\" + mtrl[i].TextureFilename);
}
}
}
}

private void SetupCamera()
{

Camera cam=world.getCam();
device.Transform.Projection = Matrix.PerspectiveFovLH(angle, this.Width / this.Height, nearZ, farZ);
device.Transform.View=Matrix.LookAtLH(cam.getPosition(), cam.getDirection()+cam.getPosition(), cam.getUp());
device.RenderState.ZBufferEnable=true;
//device.Transform.View = Matrix.LookAtLH(new Vector3(0,0, 580.0f), new Vector3(), new Vector3(0,1,0));
//device.RenderState.Ambient = Color.DarkBlue;
device.Lights[0].Type = LightType.Directional;
device.Lights[0].Diffuse = Color.White;
device.Lights[0].Direction = new Vector3(0, -1, -1);
device.Lights[0].Commit();
device.Lights[0].Enabled = true;

}

protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
{
DateTime time = DateTime.Now;
TimeSpan passed=(time.Subtract(previousTime));
passedTime += (passed.Ticks);
previousTime = time;
//Discrete Timing Loop
while (passedTime>TICKS_PER_GAMESTEP)
{
world.step();
ic.UpdateState();
passedTime-=TICKS_PER_GAMESTEP;
}
device.Clear(ClearFlags.Target | ClearFlags.ZBuffer , Color.CornflowerBlue, 1.0f, 0);
SetupCamera();

device.BeginScene();

LogFile lf=LogFile.GetInstance();
lf.WriteLine("About to Screen Capture");
ArrayList ships=world.screenCapture();
lf.WriteLine("We have an arraylist.");
lf.WriteLine("size of ships is: "+ships.Count);
foreach(Unit u in ships)
{
lf.WriteLine("Rendering a ship.");
u.render();
}
lf.WriteLine("Scene Ended.");
device.EndScene();
lf.WriteLine("Presented.");
device.Present();

this.Invalidate();
}

private void DrawMesh(float yaw, float pitch, float roll, float x, float y, float z)
{

device.Transform.World = Matrix.RotationYawPitchRoll(yaw, pitch, roll) * Matrix.Translation(x, y, z);
for (int i = 0; i < meshMaterials.Length; i++)
{
device.Material = meshMaterials[i];
device.SetTexture(0, meshTextures[i]);
mesh.DrawSubset(i);
}
}


///
/// Clean up any resources being used.
///

protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

#region Windows Form Designer generated code
///
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///

private void InitializeComponent()
{
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(1016, 734);
this.Name = "Form1";
this.Text = "Nova Force";

}
#endregion

///
/// The main entry point for the application.
///

static void Main()
{
using (Form1 frm = new Form1())
{
// Show our form and initialize our graphics engine
frm.Show();
frm.InitializeGraphics();
// frm.InitializeInput();
Application.Run(frm);
}
}
}
}


The most relevant code is probably the InitializeGraphics function, which I''m posting here:
public void InitializeGraphics()
{
// Set our presentation parameters
PresentParameters presentParams = new PresentParameters();

presentParams.Windowed = true;
presentParams.SwapEffect = SwapEffect.Discard;
presentParams.EnableAutoDepthStencil = true;
presentParams.AutoDepthStencilFormat = DepthFormat.D16;


// Create our device
device = new Device(0, DeviceType.Hardware, this, CreateFlags.HardwareVertexProcessing, presentParams);
MeshStorage.setDevice(device);
world=new Course(device, nearZ, farZ);
ic=new InputController(this, world);
}

Share this post


Link to post
Share on other sites

  • 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!