STufaro

Members

52

183 Neutral

• Rank
Member

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

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): [url="http://stackoverflow.com/questions/3818287/drawing-lines-in-3d-directx"]http://stackoverflow...s-in-3d-directx[/url] (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 ----- [size=5][b]Edit: SOLVED! And I'm very happy...See the following posts...[/b][/size]
4. How to tell if triangles enclose a volume

Emergent, alvaro, These were two great answers and a great discussion to read--I must admit I'm not following completely on the math, but the methods you've suggested make sense to me. For the purposes of the game I'm writing, I am not concerned about the fringe case Klein bottle, but that is an interesting point since a Klein bottle doesn't enclose anything I really like the painting solution, though. When I find the time to implement it, I'll give it a shot and [hopefully remember to] post the results. Much thanks for the ideas--the contents of your posts and the support of this community gives me both the confidence and the willpower to finish what I started...(when I find the time!) Best, -- Steve.
5. Limit quaternion rotation speed

[quote name='BleuBleu' timestamp='1298867108' post='4779960'] So, suppose I want to go from a rotation q1 to a rotation q2 and I don't want to rotate by more than x radians per frame. I tried this, but for some reason, it seem to introduce some unexpected rotations from time to time, any idea why? 1) Find delta rotation that will transform q1 into q2: delta = q2 * q1.Inverse() 2) Convert delta rotation to axis + angle 3) Clamp the angle to x 4) Reconstruct new (clamped) delta rotation 5) My final, clamped rotaiton should now be: delta * v1 Ideas? Suggestions? Thanks! -Mat [/quote] Mat, I'm not sure where the unexpected rotations come from--are you using Euler angles at any point? They might be because of a phenomenon known as gimbal lock--see this wiki article: [url="http://en.wikipedia.org/wiki/Gimbal_lock."]http://en.wikipedia....ki/Gimbal_lock.[/url] This happens when you go to Euler angles from quaternions (quaternions avoid the problem), because you have a series of rotations, and depending on which order you apply them (e.g., X-Y-Z, Z-X-Y), it may change things. That shouldn't affect axis-angle, though, but my hunch is the way to get around it is just keep everything as quaternions. I know that you can simply add two quaternions and divide them to "average" them out, resulting in a smoother transition. I had an application where there was a tank rolling over a heightmap--I noticed the tank "snapped" to the normals of each triangle it rolled over, so I averaged the normals between frames and smoothed the transitions a lot. [code] Quaternion approach (Quaternion initialRotation, Quaternion finalRotation) { return (initialRotation + finalRotation)/2; } [/code] If you keep feeding that back into itself after each frame, you'll get a fast movement at first and a slow movement toward the end, which looks nice. Using the same principle, you can get a quaternion somewhere between your initial and final: [code] Quaternion approach (Quaternion initialRotation, Quaternion finalRotation, float position) { // position between 0 and 1 return (1 - position) * initialRotation + position * finalRotation; } [/code] Correct me if I'm wrong, or let me know if that helps. Best of luck, -- Steve.
6. How to tell if triangles enclose a volume

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: [url="http://www.vfxoverflow.com/questions/81/getting-the-volume-of-an-arbitrary-closed-mesh"]http://www.vfxoverfl...ary-closed-mesh[/url] [url="http://forums.cgsociety.org/archive/index.php/t-754789.html"]http://forums.cgsoci...p/t-754789.html[/url] 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: [img]http://i56.tinypic.com/263x4kh.gif[/img] 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: [img]http://i54.tinypic.com/15pmmo8.gif[/img] 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. Regards, -- Steve.
7. DX11 [slimDX] textures on the simpletriangle

Your HLSL shader that you posted -- is that the complete shader? You never defined "txDiffuse," so it'll tell you that it doesn't exist when it tries to compile the shader. You're going to want to take a look at Riemer's XNA or Managed DirectX tutorials for this problem; it's explained nicely. This has exactly what you're looking for: http://www.riemers.net/eng/Tutorials/XNA/Csharp/Series3/Textured_triangle.php The basics as I understand them in DirectX 9 are this: You need to set up a shader with a texture sampler (tells the graphics card how to pick/generate pixels from the texture). You then set the texture in the shader in your C++ program, and the sampler figures out how to color the pixels from the texture you fed it and your pixel shader code. I don't know if it's exactly the same for Direct3D 11, but something tells me the HLSL interaction part should be similar. Best, - Steve.
8. Rotating Camera For Different Views

My brain is fuzzy and I haven't messed with computers in a while, but I'll take a random stab. You are rotating the camera 40 degrees one way and 40 degrees another way to produce 3 different views, and the camera has the same projection matrix for each view (as I understand it). I think you need to take a step back and look at that projection matrix. The way I would do it is this: your total FOV angle should be whatever you want it to be (across the three monitors). Let's say this is 180 degrees (that would mean the edges of the left and right monitors are lined up with your ears, I guess). I'd take 180 degrees and divide it by 3. I use that FOV angle in my projection matrix for each camera. Then I rotate each of the end cameras by the FOV angle left or right and get their view matrices (I think you have that part down, but 40 degrees is not the right number for the FOV angle you're using). What is your FOV angle? Remember you don't want the views to overlap, so the larger the FOV angle, the more you have to rotate each camera so the views sync up. As for the other stuff: The math gods may correct me if I'm wrong, but aspect ratio and resolution shouldn't matter. It should be all in the projection matrix as far as I know. I don't know that I helped and you might have already tried all that, but let me know if you have any other thoughts. I'm curious about this problem. Best, - Steve.
9. Real-time lens blur

Hodgman, I'm sorry I haven't been on GD Net as religiously as I would have liked to be to follow this! This is truly excellent, and I don't think anyone minds you treating this thread like a dev-blog. At least I don't :) So the sub-offset was the way to go--good find for working on the downsampled map! I think my curiosity about the specular value of the pixels might have been too much work per-pixel, so I'm very happy to see the downsampled map work in some way (even if it worked "as fast," it would still bug me that it was per-pixel for some reason). Thanks for keeping us posted on the technique--one day I'll write a game and look back to this :). I think your DOF blur implementation will complete it and give you a very convincing effect once you've tweaked it as necessary. Nice job! ratings++; -- Steve.
10. Fastest way to render text?

Oh, I see; so each letter is in its own bitmap file? FillRect() is a GDI thing, not a DirectX-based function, am I right? I don't know where DirectX comes into this, but I have an idea for you if you're using Direct3D. I'd put all my letters in one bitmap, evenly spaced apart (or not--depends on what you want to do). Then I'd let 0 = A, 1 = B, 2 = C. Then I'd make a strip of vertices that's just a bunch of connected squares, with double vertices at each overlap. Then I'd put a letter on each square with texture coordinates. So, my bitmap file of the alphabet stores each letter as a 32x32 square let's say: A B C D E F G H I ... etc. I make a horizontal grid of vertices, with doubles on the overlapping edges of the individual squares I'm trying to form. 1 2/5 7/9 11 3 4/6 8/10 12 That's 3 square right there. Now I want to write "CAT"; I know C = 2, A = 0, T = 19. If I have 26 letters in my bitmap, I know that there is a texture coordinate of 1/26 between the letters (remember texture coordinates go from 0 to 1). Now I start setting some texture coordinates. C = 2. So I set the following texture coordinates (U, V) for each vertex for the letter C: 1: (2 * 1/26, 0) 2: (2 * 1/26, 1) 3: (3 * 1/26, 0) 4: (3 * 1/26, 1) A = 0. So for A: 5: (0 * 1/26, 0) 6: (0 * 1/26, 1) 7: (1/26, 0) 8: (1/26, 1) T = 19. 9: (19 * 1/26, 0) 10: (19 * 1/26, 1) 11: (20 * 1/26, 0) 12: (20 * 1/26, 1) And I'm done. Does that work for you, or do you need something in GDI?
11. Fastest way to render text?

Have you tried using fonts? http://msdn.microsoft.com/en-us/library/bb173961%28VS.85%29.aspx
12. Incorrect shader/normal issue in Directx

Excellent! I've never had to deal with a coordinate system mix-up, but now I know what one looks like. And I know what you mean about long works in progress... Anyway, glad I could help throw stuff out there. -- Steve.