Ataru

Members
  • Content count

    432
  • Joined

  • Last visited

Community Reputation

133 Neutral

About Ataru

  • Rank
    Member
  1. I have an event handler that gets a KeyDown event, and processes some KeyEventArgs modifiers. I'd like to call another event handler that handles all of the un-handled modifiers. I.e. if foo(KeyEventArgs e) handles e.Alt and e.Shift then foobar(KeyEventArgs e) would only see e.Ctrl etc... At first I thought i could set the modifiers to false. i.e. e.Shift = false, but I can't since it's read only. I don't mind creating a new KeyEventArgs and set the modifiers, but I don't know how to do that. The handled flag is fine if you handled the entire event, but not if you partially handled it. Any ideas?
  2. Cube maps are often used for environment mapping. I think what you where thinking about was texture projection, where a 3D image texture is "applied" on an object. A cube map is usually some sort of environment, and most often is a cross, or 6 seperate images. (top, bottom, left, right, front, back.) The reflection of the cube is computed per texel, and then rendered. This allows you to render things such asreflections of the surrounding environment appear on your objects. A more advanced technique has each object render the top/bootom etc... images in real time. That's how car racing games have cars and environments properly reflecting on other cars. As for the code, I have never done cube mapping in fixed function OpenGL (just in the shader) so I can't really help you code wise.
  3. That algorithm (triangulate, then join back) is a great one. Thanks for the great reference.
  4. I'm looking for an algorithm that splits up a concave polygon into a minimal number of convex polygons. Can anyone point me in the direction of a good resource on the subject? I've tried looking up some resources but I've had little luck. Thanks
  5. Yikes! You're right. For some reason I remembered C++ as being able to distinguish the type and call the appropriate method rather than being cast, but running that code it seems to do the same thing. I guess there isn't a way to make things elegant, and I'll have to handle each "node" type seperately. My mistake, and thanks for poiting it out. I no longer have to be mad at C#, now I can be mad about both languages :)
  6. This is what I hate most about c#. It casts NewNode into Node for me. After all, the whole idea of polymorphism is that I don't need to know what kind of "node" I pass into this method. It knows it's own type. It's really quite wasteful IMHO to have to write an Accept method for every possible type of Node. In my opinion, this is one case where C++ got it much better than C#. At least I figured there must be a way to cast it back to the original type. Urgh, it's frustrating because the entire visitor pattern breaks down in C# because of stuff like this.
  7. Getting the hang of C#, but some of the ways it handles inheritance differently from C++ is driving me crazy. Take a look at this example,(obviouslu not real, class Node { } class NewNode : Node {} class Visitor { public void Accept(Node n) { Assert.IsTrue(false); } public void Accept(NewNode p) { Assert.IsTrue(true); } } class Foo { public Foo() { NewNode fooBar = new NewNode(); Visit(fooBar); } public void Visit(Node n) { Visitor v = new Visitor(); v.Accept(n); } } Unlike C++, which would pass, the C# version of this code fails. The reason (I am guessing) is that even though the n in Foo.Visit is of type NewNode, it gets cast to Node, and so Visitor.Accept(Node n) is called instead of Visitor.Accept(NewNode n) Running it through the debugger, c# obviously knows that the variable is of type NewNode, but it won't call the proper function. Is there a way to at least cast back to the original type in Foo::Visit so that it does call the proper method?
  8. Thanks, I'm rather dissapointed in some of the C# design decisions. It's strange to me that the person defining the object/struct is also deciding how the object is passed in. Oh well, react, adapt and move on.
  9. The structs where not written by me, and I can't really chane them. They store vectors/matrices etc... and I just want a list of them, that I can edit like so: holdsManyThings.myList[0].X = 25 or something like that. If the value in the list is a struct this results in compile errors (much to my surprise, it took me quite some time to even realize that the problem was relating to structs.)
  10. Ahh, I love learning yet another new language. And now I've just learned the truth behind references and how they relate to structs/classes in C#. If I have a list of structs, when I access the list by index I get a return by value, and not by reference. If I need to access these structs by reference, is there anything I can do? I know I can write a class that contains the struct, but is there a way to specify that a List contain references to structs rather than values? What I have is something like this: (One more complication is that the object stored in the list is unknown) class holdsManyThings<T> { public List<T> = new List<T>(); } But since T is sometimes a struct I'd really like to do something like this: class holdsManyThings<T> { public List<ref T> = new List<ref T>(); } which I realize doesn't make much sense syntax wise, but I think you know what I mean. Is the only answer to encapsulate my struct in a class object?
  11. I'll look into refactoring some thing so that I don't need the static type, otherwise I'll just have to override Value. Thanks (It is cool to know that it can be done though, even if it's a bit of a hack.)
  12. Yes the static members are definitley needed. I'm aware of the solution to override the Value method. I was just hoping that there would be a way of solving this problem without having to modify fooBar. Now all of my classes that derive from foo need to override this, and I was really hoping to avoid that.
  13. You guys did great with my last one, so here's another I can't figure out. My example: class foo { public static int value = 1; public int Value { get { return value; } } } class fooBar : foo { new public static int value = 2; } Now I test this: foo one = new foo(); fooBar two = new fooBar(); Assert.AreEqual(1, one.Value); Assert.AreEqual(2, two.Value); <- FAILS, Value == 1 I am guessing that the base class is unaware that the derived class overwrites the value parameter. Is there some way to tell it, so that the proper value is returned?
  14. Suppose I define a base generic class foo<T> and two class derive from this class fooBar : foo<int> fooBar2 : foo<double> Can I store a generic list of base class foo? Something like this: KeyValuePair< string, foo > genericList; I get compile errors because the compiler wants me to specify the type for foo, but I actually want to store references to the generic foo base class. In this way I can access fooBar and fooBar2 in the same dictionary. Is such a thing possible in c#?