• Advertisement

alex_myrpg

Member
  • Content count

    334
  • Joined

  • Last visited

Community Reputation

351 Neutral

About alex_myrpg

  • Rank
    Member

Personal Information

  1. Unfortunately C# does support collection intializers but not "dictionary initializers", which means there's no syntactically elegant way to do this. I would recommend passing the attributes as name/value pairs (strings separated by a single char delimeter). You could define your Create method as such: public void Create(string tagName, string content, params string[] attributePairs) { var attribs = attributePairs.Select(val => { var parts = val.Split(new char[] {':'}, 2); return new {Name = parts[0], Value = parts[1].TrimStart()}; }).ToDictionary(item => item.Name, item => item.Value); var cssClass = attribs["class"]; // example usage // ... } This means you could call the method as follows: Create("div", "text content/more tags", "class: myClass", "style: background: white;"); Given that the C# language does not have built-in support for maps/dictionaries (unlike javascript for example), I'm fairly convinced this is the nicest way to do it. Hope this helps.
  2. speed of a revolving object?

    Quote:Original post by ahlywog Quote:Original post by Fingon @Bob Janova: I think you actually mean that the speed of an object undergoing circular motion is v = ωr where r is the radius, ω = 2πf = the angular frequency (i.e. radians swept out per second), and f is the frequency, i.e. number of revolutions per second). So to make sure I'm following you...say I have the following variables: r = 10 f = .1 #revolutions per second you said v = 10 * (2 * PI * 0.1) Or v = 6.28318 Is that right? Yep, that's correct. Circular motion, at least when uniform (constant speed), is actually quite a straightforward topic provided you've gotten your head around the meaning/physical interpretation of all the variables (elliptical motion is rather more difficult). If you want a brief overview of the maths of circular motion, see the Wikipedia article. It has a pretty helpful diagram, but notice that the article uses lower and upper case omegas interchangeably for angular frequency.
  3. [.net] Padding with tabs

    The short answer is no, not without knowing how many spaces a tab represents in whatever text viewer you are considering. This is typically why it is recommended to use spaces rather than tabs for formatting plain text into columns. I would just stick with the method of space padding unless you have a particularly good reason to use tab characters.
  4. speed of a revolving object?

    @Bob Janova: I think you actually mean that the speed of an object undergoing circular motion is v = ωr where r is the radius, ω = 2πf = the angular frequency (i.e. radians swept out per second), and f is the frequency, i.e. number of revolutions per second).
  5. Unless I misunderstand you, I think you simply want to declare: public static uint someNum; What you referred to as a "static variable" is actually a static property with a backing variable. You can use that design if you like (it is often recommended in fact, for various reasons), but a variable declared as above will do the job if you're simply using the class for global storage. Now if you just want a certain class to be accessible only statically (i.e. no instances can be created), then it's also advisable to declare it as such: public static class SomeClass { // ... }
  6. Glad to help... Indeed, it is probably wise to wrap it in another class, as then you can make certain optimisations (such as using TryGetValue) or implement an enumerator, besides from the simpler syntax of course. Be aware of one disadvantage, which is slower add/remove times (especially under certain circumstances) compared to using a single list. On a side note, (if you're using .NET 3.5) you may want to take a look at the System.Linq.Lookup<TKey, TElement> class, along with the ToLookup extension method. Although you can't directly use Lookup as a modifiable collection, it's useful when you want to transform other types of collections/lists into a lookup table (multi-key collection). Using it together with an ordinary List<T> is in fact the better option *if* you tend to be adding/removing items more often than you retrieve them.
  7. I believe HybridDictionary will give you the same problem. Also, I'm not sure what the Map class to which Bob Janova refers is, but a Dictionary<TKey, List<TValue>> should do the job for you. If you want to simplify the process of adding/removing entries, then you can just wrap the object in your own class (and use an indexer perhaps).
  8. Sucking a ball

    I presume this is a 2D environment, which should simplify matters somewhat. Now if you want a discrete cut-off when the ball is outside of the triangle, then a simple point-in-triangle test will do the job, as ToohrVyk mentions. If however you want the power to fade with deviation from a certain angle (as well as radially), there are simple methods for that too. For the discrete (on/off) behaviour, you'll just want to use something like the inverse square law for calculating the force acting on the ball (directed towards the "sucker" of course), setting the force to zero whenever the ball is outside of the triangle.
  9. Extracting yaw from a normalized vector?

    If you just want the yaw relative to the positive x-axis, then this should do: yaw = atan2(n.Z, n.X) (If you need to find the yaw relative to some arbitrary coordinate system, then you'll have to use a simple matrix transformation first, but don't worry about that if you're just measuring in standard world space.) See here for the definition of atan2 if you're not sure. The function is included in the standard maths library of pretty much every language.
  10. I can't be sure without knowing what you're trying to accomplish in the end - but I would recommend avoiding regex (which is really overkill here) and using text parsing functions instead. You should be able to write an enumerator function (using yield return, etc.) to do the job in less than 5 lines. You'll also have something much more readable if you can avoid regexes.
  11. Free Softbody Physics?

    Jello Physics is a very good soft-body 2D physics engine for .NET. Samples are for XNA, though I believe the library is independent of the graphical framework. Haven't heard of any 3D ones for .NET, though I'm sure there are a few for C++.
  12. Moving a circle between two points

    Unless you want to reformulate all the necessary equations of dynamics to work in reverse, you'll really want to go with an iterative method of some sort. It's far from a cheat, and is commonly used in physics and games for various reasons. If you still want to pursue your current approach, then hopefully some of the maths already posted here has made everything clear.
  13. Moving a circle between two points

    Yeah, I was referring to the AI. But you'll simplify matters hugely by simulating the shot made by the AI and using an iterative approach to improve its precision.
  14. Moving a circle between two points

    Ah, now I understand what you're trying to accomplish... This sounds like a sensible way to check whether the ball will be potted, though of course it won't be completely reliable. However, I suspect it may be best just to use the physics engine to simulate everything.
  15. Moving a circle between two points

    What are you actually trying to accomplish? We really need to know this before you can expect a full answer. Also, my first post should effectively answer your most recent question. Turn the inequality into an equation and solve to find: theta = arcsin((diameter of circle) / (distance between two points))
  • Advertisement