Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 16 Feb 2007
Offline Last Active May 15 2015 09:58 AM

Topics I've Started

inverse world matrix and per-triangle picking

12 September 2012 - 04:09 PM

Once again I'm having fun with linear algebra...or so I think right now.

I have picking methods in my level editor that work great for my mesh objects, except when it comes to scaled meshes. I apply an inverse of the mesh's world transform matrix to get the ray from world space into object space, and rotation/translation don't give it any problems. When I scale a mesh up in size, the algorithm no longer lets the ray hit the mesh correctly, and I get a lot of null results on the collision check.

I'm assuming its because the inverse of a scale operation is going to do something wierd to the ray, as I can't grasp at the moment what it's going to do to a single point...I'm assuming scale it relative to (0,0,0) which will...wait, no, that would bring a correctly un-rotated/un-translated ray closer to the object's origin, which makes sense for a scaled up mesh relative to its base 3d coords.

Okay, I don't know then. I'm likely missing something else in the code like the last time I had a question on matrices and vector spaces. But if my guess is off, I'd be happy with any enlightenment.

Trouble combining two projection spaces?

07 September 2012 - 08:53 AM

Hi all,

Here's the setup:
I have a deferred rendering chain that renders all world-space items to several targets, then does screen-space calculations on those targets to get my final result, which is then rendered onto a screen-facing quad in an orthographic projection that is drawn to the backbuffer and presented.


World content -> World-View-PerspectiveProjection matrix -> gbuffer -> textured to quad -> orthographic projection matrix -> screen.

This is all for a level editor, which lets you paint directly on the terrain and manipulate terrain structure, etc. One thing I'm trying to do is draw the "border" of the paintbrush on the terrain, and I already have reverse projection in place for picking, so I know (in world-space coordinates) where the mouse is pointing at all times. My brush border is a linestrip that is drawn relative to that world-space point.

Here's the specific question:

I want to draw the brush border as it lays on the terrain. I get its normalized coordinates (in the -1,1 range on all three axes) by applying the same worldViewProjection matrix that I use to draw the rest of the world content. I'm trying to draw the resulting linestrip on TOP of the ortho view of the textured quad that shows my deferred results (so that the color of the linestrip isn't affected by any of the pixel shaders that combine my deferred buffers). If both an ortho projection and a perspective projection translate coordinates into the same normalized space, why doesn't the brush circle (technically an ellipse in all but a straight-down view) show up correctly in the view?

A few extra notes:

-My ortho view is built with the viewport width and height of the WinForm it's built into, depth range .1 - 10, with the textured quad at z=10 just to put it as far back as possible.
-The normalized z-depth of the brush radius is usually around +.7 - +.9 given the perspective projection is given a depth range of 4-1000.

-The brush verts are drawn to the backbuffer via a shader that only uses the world-view-projection matrix, AFTER the textured quad is drawn to the backbuffer using the ortho matrix.

-My expectation is that I would get an ellipse (my brush circle from the camera perspective) overlayed on the ortho view of the textured quad. Instead, I get the attached image. This has to be a stupid Linear algebra mistake, but I'm not sharp enough to see it right now.
Attached File  exampleView.jpg   32.35KB   50 downloads
The green line is my problem. That should be a circle drawn onto the terrain at the mouse point. What am I forgetting or incorrectly assuming?

[.net] Using a dictionary with methods as value in key/value pair?

25 May 2010 - 07:16 AM

General question, I'm trying to build an input manager class for XNA. Is it possible to use a method or delegate as the value in a Dictionary? My thought was to have each game state (paused, inCombat, travelling, inMenu, etc) contain its own key mapping dictionary, so that the input manager class just takes in the key/button press and feeds it to the current state's (in a state stack) key mapping dictionary, where the value of the dictionary entry would be a related method like "moveForward()" versus "cycleThroughMenu()" for a press of Keys.Up. Knowing what I'm trying to do, if my idea isn't possible, might anyone else have suggestions? This is my first time trying to design an input handler that doesn't just rely on 500 if(KeyboardState.isKeyPressed(Keys.A)){dostuff();} statements.

Looking for suggestions on OOD texts

30 April 2009 - 07:05 PM

I've just completed my second semester of a CS degree (we wrapped up with data structures in the core programming course) and feel like my two biggest weaknesses thus far are in algorithm design (which I'm sure will come with practice and/or a discrete math course) and OOD. When I sit down to create a program from scratch, I find I'm still thinking largely in linear patterns, and any time I look at tutorials or sample code I understand their idea and the implementation-- but I would never have thought do do things "that way." So...are there any books anyone here has found integral to really grasping-, and adding to your standard process-, OOD? I'm picking up the Gamma et al. Design Patterns book in a week, but any insight/experience would be much appreciated.

[C++] Debugging assistance with Visual C++ 2008 EE

22 October 2008 - 04:35 AM

Hello again all, I'm currently working on a simple array-usage program, but any time the program loops through, a specific value in the main 2-dimensional array gets changed. I'm having trouble catching exactly where (or why) that value is changing, but I've added a line to my code to tell me the value of that "cell" at the end of each run-through of the program's main loop, so I do know it's getting changed and not just failing to print. My question is then this: is there a way for me to flag that cell in the array so I can catch where in the program it's getting changed? I don't know if there's an easy debug option to do this(I see a "conditions" column in the breakpoints tab of the IDE, but can only seem to set breakpoints on functions themselves) or some bit of code I could add that checked for a change in value. Any ideas or input would be greatly appreciated, as always.