Jump to content

  • Log In with Google      Sign In   
  • Create Account

Banner advertising on our site currently available from just $5!

1. Learn about the promo. 2. Sign up for GDNet+. 3. Set up your advert!


Member Since 27 Jul 2006
Offline Last Active Sep 02 2012 12:19 PM

Topics I've Started

[Solved] Thick (Constant-Width) Lines Using Quads

26 December 2011 - 04:42 PM

Hi all,

I am making a 3D level editor for my game and would like to add grid lines, but ones better (namely, thicker) than the thin 1-px lines created by rendering a LINE_LIST. I've run across several posts using D3DXLine, and tried it myself, but found that the transforms were buggy, so I set out to make 3D lines from quads aligned to face the camera (i.e., billboards). I do not completely understand billboards, but I've been playing with them long enough to have a general feel of how they work and can create some on my own.

I would like to keep the lines a constant thickness, no matter how close or far the camera is from them. I tried using an orthographic projection to no avail, and I've also tried doing a perspective divide manipulation (or rather, multiplication) on my billboard's vertices to find out how much I should scale them. No attempt so far I've made looks even remotely correct, and I think I'm just confusing myself trying to mess with different things for an easy solution...

Can anyone outline the basic steps of how I would go about doing this (e.g., step 1, make quad vertices, step 2, rotate, step 3...etc.)? How would you solve this problem?

An external link of someone solving the same problem, but without perspective (plus I'd rather not use a vertex shader and am having trouble understanding his assembly code):

(Just a note--working in Direct3D9 via SlimDX and C#, so that's why I reference Direct3D-specific names, but I have no need for API-specific examples--anything should work for me.)

Best regards,
-- Steve


Edit: SOLVED! And I'm very happy...See the following posts...

How to tell if triangles enclose a volume

27 February 2011 - 08:21 PM

Hi all,

I was wondering if anyone might know where to start on this problem:
Given a bunch of primitives (triangles in my case), ensure that they completely enclose at least one volume.

My initial approach was to make sure all the edges were matched up with those of other triangles, but I also wanted to allow for the faces of primitives to enclose volumes (leaving the edges free and "hanging" off the side), or for a primitive to be connected to one of the faces of the volume by only one edge.

I did some Googling on the matter and found these things related to Maya:

These work on the assumption that there's already a closed volume in the first place, or that having a free edge is bad, which are not necessarily true in my case.

Thinking more robustly: from a programming perspective, I thought I could begin by testing all my triangles to see if they enclose a volume. The minimum is four triangles (a tetrahedron), so I would have to test all my triangles that share three edges with others in groups of four (in all combinations), then in groups of five (in all combinations), six, seven, and so on. That method only accounts for edge-connected triangles. So this:
Posted Image
which is a poorly-drawn pyramid stuck to a square plate (completely enclosed, but with free edges--should pass my test) would be rejected, even though I want to accept that.

However, this triangle stuck to the top of a closed cube, also okay by my standards, would pass successfully:
Posted Image
But, since that figure would be made up of 9 triangles, it would take (at most) 1784 tests (http://www.wolframalpha.com/input/?i=13+choose+4+%2B+13+choose+5+%2B+13+choose+6+%2B+13+choose+7+%2B+13+choose+8+%2B+13+choose+9+%2B+13+choose+10+%2B+13+choose+11+%2B+13+choose+12+%2B+13+choose+13) to figure that out.

Note that in that last case the triangle's bottom edge spans a face that would be made up of two separate triangles--that adds an extra wrinkle to the problem, I guess.

So, not only does my method require n C 4 + n C 5 + ... + n C n - 1 + n C n tests at most (where "C" means "in combinations of" ;)), but it doesn't immediately take care of the other cases I want to allow for either.

Might anyone be able to come up with a better method off the top of his/her head? I'm stumped on this one.:blink:

-- Steve.

[C#] Dictionaries of same-base-class objects

30 July 2009 - 10:15 AM

I have been programming a graphics class in C# and SlimDX, and my graphics class has two classes of objects ("mesh" objects and "vertex" objects). Both "mesh" and "vertex" objects inherit from a base class, "object", which has properties like Position, Scale, Rotation, BoundingBox (etc.) general to both types of object. I have separate dictionaries of both types of object. When I want to check each object for collision against another, though, I want to check it against all objects. Is there a way I can do this in one loop? Here's what I want to do:
foreach (object Object in (vertexobjects.Values and meshobjects.Values))
    CheckCollision(Object, testobject)
If there's no way, I have to loop through the dictionaries separately, which, while okay, is not preferred, as I plan on adding other types of object to my game as well. Much obliged, - Steve.

Terrain Following/Smooth Transitions Between Triangles

24 July 2009 - 10:43 AM

Hey all, I have two problems I've run into that I was hoping I could get help for. I have a pretty good terrain following "algorithm" (if you could call it that) for my tanks and stuff that I have rolling across my terrain: I align the normal of the object with the normal of the terrain. To do so, I rotate my object by two angles, one angle about the X-axis, and one angle about the Z-axis. I calculate those angles by finding the X and Z angles the terrain triangle's normal makes with the Y-axis, then rotating my object by those angles (but since the angle between vectors is always positive, I make it negative when the tank is going "downhill"). So far so good when the tank is moving in the positive or negative Z direction. The problem is when I turn my tank and try to roll it in a different direction (i.e., change the yaw angle and rotate around the Y-axis), the tank doesn't line up much with the terrain. When I try to make it go in the +/- X direction, the effect is very noticeable. I realized I needed a way of making X-axis rotation angle become my Z-axis rotation angle and vice versa when the tank was fully rotated in that direction. I did some research and came across quaternions (which I've never understood fully) and gimbal lock, which I believed was at least part of my problem. I converted my Euler angles to quaternions, and then constructed my rotation matrix from a quaternion, hoping that would solve the gimbal lock problem, but it didn't, so I'm not sure that that did anything. I realize ultimately what I'm trying to do is rotate my tank around an axis that is my terrain's normal. So problem 1 in short: is there a way I can perform a RotationAxis using Euler angles (e.g. doing it as RotationX * RotationY * RotationZ)? If not, is there a way I can do it using quaternions if I know the tank's yaw angle, its normal (0 1 0) and the terrain normal? The second problem is a little easier, I've had some ideas on how to solve it: When my tank follows my terrain and adjusts to each triangle's normal, it kind of snaps and pops as it crosses triangles. I guess I should probably try smoothing its transition between normal points. What is the best way to do that? Is there a way I can determine how far across the triangle boundary the tank is to "blend" the two normals? I was thinking that if all else fails I'll just determine my angles by sampling the height at 4 points on the bottom of my tank (or car) to find the angles, but that means that I have to find the ideal 4 points for every mesh (i.e., the wheels) in advance, and I feel that that would inhibit me when I start adding objects in my game with the introduction of that manual preprocessing step for some kind of annoying metadata :). Thanks for your help. Much obliged, Steve.

[SlimDX/C#] Effect.FromMemory fails with FXO files

23 July 2009 - 09:07 AM

Hello all,

I am working in C# and DirectX 9 via SlimDX. I have the following:

            string[] effectPath = EffectPaths;
            for (int i = 0; i < effectPath.Length; i++)
                if (System.IO.File.Exists(effectPath[i]))
                    byte[] effectdata = File.ReadAllBytes(effectPath[i]);
                    string errorList;
                    MyEffects[i] = Effect.FromMemory(D3DDev, effectdata, null, null, null, ShaderFlags.None, MyEffectPool, out errorList);

My effects are .FXO files compiled with fxc.exe under VS and PS 2.0.

Effect.FromMemory fails with D3DXERR_INVALIDDATA: Invalid data (-2005529767)

...this has been puzzling me and I haven't been able to find anything on it. Is it obvious what I'm doing wrong?

Much obliged,