• Content count

  • Joined

  • Last visited

Community Reputation

221 Neutral

About Tristan85

  • Rank
  1. Interpolate spline with constant speed

    Hi guys,   Perhaps the problem is somewhere in my current implementation. Every function in my spline class seems to work fine on it's one, except for the InterpolatePositionByDistance() function.   See below: public Vector3 InterpolatePositionByDistance(float s) { //Assertions.Assert((s >= 0.0f) && (s <= Length));    const int n = 20;  // step size    float t = 0;    float h = length / n;    for (int i = 0; i < n; ++i)    {     // The divisions here might be a problem if the divisors are     // nearly zero.     float k1 = h / InterpolateDerivative(t).magnitude;     float k2 = h / InterpolateDerivative(t + k1/2).magnitude;     float k3 = h / InterpolateDerivative(t + k2/2).magnitude;     float k4 = h / InterpolateDerivative(t + k3).magnitude;     t += (k1 + 2 * (k2 + k3) + k4) / 6;    }    Debug.Log(t); // when s == length, and #segments > 1, t > 1 (for example t == 4.12334) return InterpolatePosition(t); }     For full source code, check the Spline class in attachment.   Kind regards, Tristan
  2. Hi guys,   As hinted at by the topic title, I'm currently trying to move an object along a parameterized curve with constant speed. Following advice in several older forum posts, I'm using the numerical solution for reparameterization that's presented at page 8 of this paper.   This works great for the simplest case, in which there's only 1 segment. But when calling GetCurveParameter(curve.length) for a curve with more than 1 segment, it will return a t-value which is much larger than 1 (my chosen tmax).   The solution is most likely described at page 11 ("Handling Multiple Contiguous Curves"), but I'm having trouble understanding the how and why of this approach. For example the comment that says // We know that LSegment[i-1] <= s < LSegment[i].  seems wrong to me, given that earlier code seems to fill the LSegment array with the length of each segment.   If anyone here could help me understand this in any way, I would be much obliged!   Thanks in advance,   Tristan    
  3. In my current and past projects, several things have helped me to keep track of code structure: - strive for a clean design with minimal dependencies between parts (as these are hard to keep track of) - make code as "self-documenting" as possible (i.e. use descriptive variable, class and function names) - make UML class and/or activity diagrams depicting the public interfaces of high-level components - when working in a team, make sure a single team member is responsible for each piece of code (so you can quickly ask a person to refresh your memory) - use comments wisely (in my opinion, never to explain syntax...always to explain semantics) Something I don't do quite often enough, but which might help as well: - create unit and/or integration tests that demonstrate typical use cases for a (collection of) class(es). I hope this might help a bit, and would be interested to read some additional insights.
  4. need help on a simple math equation.

    Thank you all for these elaborate and insightful replies. (Whether they were written down whilst being intoxicated or not.)
  5. need help on a simple math equation.

    @Brother Bob Fascinating! I'd be quite interested to learn how you've managed to derive the formula from the OP's data. Could you perhaps elaborate a little?
  6. Flabby Physics

    Hi everyone, The other day I came across this flash game, and was struck by its apparent simplicity. [url=""][/url] In practice though, I don't have a clue about what technique is being used to deform these objects. Is this a spring-mass system? It all seems so stable... I'd love to learn more, as I can definitely see the potential of this technique, and would like to play around with it a bit. Kind regards, Tristan
  7. Design problem

    Thanks to the OP, dmatter and TheOrzo for the well-frased question and answers in this post. Added to my favorites!
  8. According to some people, constructors should only be used to bring the object in a valid state. So, they would propably argue that the logic contained within the constructor should be so minimal that there would be virtually no errors. In these rare occasions, throwing an exception makes perfect sense to me. Personally I also believe in the object creation = initialisation mantra, so a separate Initialize() method would be something I'd advice against.
  9. Hi xLeo, Another thing I just realized; what Vertex Format are you using? íf your vertex format includes the D3DFVF_XYZRHW flag, DirectX will think your vertices have already been transformed by you...and therefore will not bother to apply its world matrix to them. Either manually multiply them by the transformation matrix to solve this, or change your vertex format. (The 2nd option will probably be the best one, considering the fact that DirectX will probably multiply your matrices in a much more optimized manner...) Kind regards, Tristan
  10. Hi xLeo, Your code seems quite alright, except for one thing: - D3DXMatrixRotationX expects its second parameter to be specified in radians, not degrees. Whereas a full circle has 360 degrees, it has 2*Pi radians. Herefrom you can easily deduce that: 45.0 degrees * (2*Pi radians / 360 degrees) = 45.0 degrees * (Pi radians / 180 degrees) = (1/4) * Pi radians Kind regards, Tristan
  11. Storing data

    Hi dabo, I would recommend to create a logical XML structure for your data first, and only then figure out how to read it. In this case I'd suggest: <Player height='2' id='0' weight='80' name='John Doe'> <Stats> <Stat assists='4' games='20' goals='3' penaltyMinutes='32' /> <Stat assists='2' games='3' goals='1' penaltyMinutes='12' /> </Stats> <Player> To read the actual xml, you might want to check out the TinyXML library. If you decide to use SQLite instead; I'd create 2 tables to model this. - A Player table, containing the fields height, id, weight and name - A Stats table, containing the fields assists, games, goals, penaltyMinutes and quite importantly playerID. Than to get all stats of a certain player you'd be able to do something along the lines of: RunQuery( "SELECT * FROM Stats WHERE playerID='{0}'", ); Furthermore, I don't really have much domain knowledge of sports, but the fact that a player needs an array of stats in this manner seems a little odd to me. But again, I'm not exactly sure what you're trying to model, so it might be perfectly fine. Kinds regards, Tristan [Edited by - Tristan85 on May 29, 2009 6:13:20 AM]
  12. Hi everyone, For a chess game I'm creating as an example for my students I am currently using the MVC pattern. There is a BoardModel, a BoardView and a BoardController class. Currently the BoardController class depends on BoardView and BoardModel. BoardView depends on BoardModel. BoardModel is not dependant on BoardView or BoardController. BoardController delegates control of the board to one of two Player classes, depending on whose turn it is. The HumanPlayer class (subclass of Player) allows the player to first select a square of the board with a piece, and then select another square on the board to move that piece to. Here's where trouble begins: I want to provide some visual feedback of which squares the user is selecting. But this would either create a dependency of BoardView on HumanPlayer (part of the controller layer), or add the notion of which squares are selected to the BoardView class...but this notion is typical for the way a HumanPlayer controls the board since an AIPlayer just performs the move instantly. Summarizing: a certain type of control-mechanism (so not part of the model) should be visualized to the user. How would you guys handle such a case? Kind regards, Tristan
  13. Pre rendered depth buffer XNA

    @MJP: putting the SetRenderState calls after the Begin()-call did the trick; values are written to the backbuffer now! The only thing that bothers me a little bit is that I believe that I've read somewhere it's not great practice to change renderstates between Begin() and End()...oh well, it works ; ) @Matt: yeah, I figured as much. For now visually the values seem okay, but normalization of some sort will probably be the next step. Anyway; thanks to all your tips I think I can get the rest of it working now. Thanks a million! Tristan
  14. Pre rendered depth buffer XNA

    It was indeed necessary to compile against shader model 2.0. Version 1.0 just didn't compile. It seems like output to the DEPTH (or DEPTH0) semantic just gets ignored. I've tested this on several computers. One thing in my PIX experiment stands out: - It seems like Z-testing is disabled for some reason. I've set several renderstates to the obvious, but still no luck. Perhaps my code contains a mistake or an ommision? GraphicsDevice.Clear(Color.CornflowerBlue); // obvious renderstates GraphicsDevice.RenderState.DepthBufferEnable = true; GraphicsDevice.RenderState.DepthBufferWriteEnable = true; // try to use the depth effect while rendering: depth doesn't get written however spriteBatch.Begin(SpriteBlendMode.None, SpriteSortMode.Immediate, SaveStateMode.None); depthEffect.Begin(); depthEffect.CurrentTechnique.Passes[0].Begin(); spriteBatch.Draw(texture, Vector2.Zero, Color.White); depthEffect.CurrentTechnique.Passes[0].End(); depthEffect.End(); spriteBatch.End();
  15. Pre rendered depth buffer XNA

    Let me start by saying: thanks for your quick reply. That PIX-tool was a great tip, which confirmed my suspicion: - My 3D-models are correctly rendered to the depthbuffer, but that pixelshader-thingy doesn't write to the depth-buffer: or at least not correctly. Perhaps I should have mentioned that I'd already looked at Catalin's sample before posting here. Writing pixelshaders is admitatly not one of my specialties though...perhaps I should do some fancy conversion of my alpha-value to convert to the depth buffer format? Catalin's sample leads me to believe that's not necessary, but still... Anyway I'll continue my search for a solution on this side of the internet. Any further tips or tricks are still most welcome of course =) Thanks again, Tristan