Jump to content

  • Log In with Google      Sign In   
  • Create Account

Awesome job so far everyone! Please give us your feedback on how our article efforts are going. We still need more finished articles for our May contest theme: Remake the Classics

metsfan

Member Since 25 Mar 2012
Offline Last Active Today, 02:49 PM
-----

Topics I've Started

SlimDX Math vs XNA Math

27 April 2013 - 05:11 PM

Hello all,


Since Microsoft announced the impending death of XNA, I've decided to switch one of my projects from XNA to SlimDX.  My first impression of the SlimDX library is that it does a very nice job of providing a simplified wrapper around DirectX, and it seems like a great alternative to XNA.  However, the Math library provided by SlimDX is missing a few key components.  The two that are the biggest hamstring on me right now are:

 

1) No BoundingFrustum class

2) No Viewport class, with Project/Unproject methods.

 

Now obviously I can code these myself, but then every new project I start I have to import these classes, or create some kind of package, where as the XNA math library already has this stuff built in.  Plus who knows what else I will come across that I wish I had with SlimDX that XNA provides.  Now, even though the XNA library is dead, and the rendering engine is somewhat antiquated, the Math library to me seems timeless.  Is it crazy to abandon XNA for all rendering, sound, networking, ect, but still use the math library?  I'm sure SlimDX will catch up eventually, but for right now, it seems like the right call.  Thoughts?


Am I the only one that finds OSG's code disgusting?

03 April 2013 - 10:28 AM

So I've decided that as an exercise to learn more about engine development that I would develop a platform-independent scene graph with the ability to have renderers for multiple rendering systems.  I have heard much praise from OpenSceneGraph, so I decided to have a look at their code for ideas and inspiration.  

 

What I found instead was a sea of bad code.  In particular my gripes were:

 

1) Tons of protected member state.  This opens a HUGE potential for problems later on, and would require massive refactoring if the underlying base classes ever changed.

 

2) Every object extends from a "base object" (similar to Java), and supports only manual reference counting.  I once considered a system like this, and came to realize (with the help of others) it causes nothing but problems in the long run.  Why OSG?

 

3) Exposing getters and setters for properties that have no business being exposed.  Literally every bit of internal state can be modified through a setter, and in some cases it's extremely inappropriate.  The idea of private state is practically nonexistent in OSG.

 

4) I was expecting an abstraction of OpenGL, and found only a thin wrapper.  The idea that OSG could ever support another rendering library is basically impossible at this point.

 

Now this isn't to say I didn't take away anything positive from my dive into their code.  In fact there were several things I liked.   But overall, wow what a disappointment that was.  Is this the feeling most people get when they look at OSG's code, or am I just being too critical?


Screen-aligned Billboarding, Need help.

20 March 2013 - 08:21 PM

THIS HAS BEEN SOLVED.  Feel free to let this thread die, but I welcome any feedback.

 

Hello all,

 

I am trying to do screen-aligned billboarding of some text labels, and I am having some trouble.  The following is my code for calculating the billboard matrix:

// Up vector from view matrix
CEVector3 up = CEVector3Normalize(CEVector3Make(viewMatrix.m10, viewMatrix.m11, viewMatrix.m12));
// Normal vector from near plane
CEVector3 normal = [camera.viewFrustum planeAtIndex:NEAR].normal;
// Negate the normal vector
normal = CEVector3MultiplyScalar(normal, -1);
    
// Verify that up and normal are perpendicular.  If not, something is wrong.
double dot = CEVector3DotProduct(up, normal);
if (dot < 0.00001) {
        // Calculate the right vector
        CEVector3 right = CEVector3Normalize(CEVector3CrossProduct(up, normal));
        // Create billboard rotation matrix
        billboardMatrix = CEMatrix4Make(right.x, up.x, normal.x, 0,
                                        right.y, up.y, normal.y, 0,
                                        right.z, up.z, normal.z, 0,
                                        0, 0, 0, 1);
}

 

 

Then, to apply this matrix to a feature, I do the following.  

 

// All features are at position 0 on the z axis.
CEMatrix4 modelViewMatrix = CEMatrix4Translate(billboardMatrix, feature.position.x - cameraPosition.x, feature.position.y - cameraPosition.y, -cameraPosition.z);

 

I have tried also using the column vector of the view matrix instead of the row vector and transposing the billboard matrix, and all combinations, and nothing seems to produce the correct results.  

 

My view matrix does have some weird transformations like scaling and shearing, not typical of examples of I've seen with billboarding.  In fact, when I disable the scales and shears, the billboarding seems to work fine, but when I enable them again, it acts very very strange.  The labels do show up, but they come in from all directions as I move the scene, and most certainly are not billboarded.  

 

Can anyone spot my mistake? Any help would be most appreciated. Thank you.

 

EDIT - Update, I made the following changes:  I transpose the billboard matrix after construction, and changed my translation code to:

billboardMatrix.m30 = feature.position.x;
billboardMatrix.m31 = feature.position.y;
billboardMatrix.m32 = 0;
modelViewMatrix = CEMatrix4Multiply(inverseViewMatrix, billboardMatrix);

 

And this seems to produce billboarded text, as in the labels always face the camera, however, the labels are flush against the XY plane, rather than looking at the camera, so they are barely readable.  Still not sure how to fix this problem.

 

EDIT2 - I think I got it, by not normalizing the camera up vector, it seems to have fixed the issue.  It now appears to be properly billboarded.  I think the problem is my scale was being lost.  However, if anyone sees any errors in any of my math, please point it out, as I am certain that this is not perfect.  Thanks.


Find minimum z where object is fully visible.

13 March 2013 - 04:17 PM

Hello all, I am having trouble with a math problem, and I was hoping someone could shed some light or push me in the right direction.  The problem is as follows:

 

Suppose I have a bounding box, which axis-aligned, and lies on the XY plane.  I would like to find the minimum z-position at which this object is full visible on screen, with no parts of it intersecting the view frustum planes.  

 

Of course, one could take the naive approach of just continually incrementing the z position of the camera until the frustum test passes, but this seems like a very bad approach.  Does anyone have any other ideas for how to solve this problem?

 

Thanks.


Opinions on "Descriptor" construction pattern.

10 March 2013 - 09:22 PM

Hello all,

 

I am currently in the process of refactoring some code in my engine.  Some of my objects have many "options" which are not necessarily required parameters, but different flags and values the user can choose to set if they'd rather not just have the object use the default.   As of right now, I have my options list implemented as typedef for std::vector<std::string, boost::any>.  This seemed like a good plan at the time, but I've come to realize it's rather clunky and error-prone in a strongly typed language like c++.

 

I am looking to switch to the "Descriptor" pattern that Microsoft uses in much of it's DirectX 10 and 11 library (anyone who has used either of these libraries will know exactly what I mean).  The way I see it, if it's good enough for Microsoft, it's good enough for me.  However, every pattern has pitfalls, so I am just wondering, has anyone implemented this pattern in their projects, and if so what were the downsides/pitfalls you ran into? 

 

Thanks.


PARTNERS