• What are you working on? January 2012
    3,401 replies, posted
[QUOTE=Loli;34242274]You're actually using the "trapezium method" There. That'll only give you an estimate. To do it you need to. 1 > Intergrate (Add one to the power, divide by new power) eg. [SUP]3[/SUP][SUB]1[/SUB]&#8747; x[B][SUP]2[/SUP][/B] + 3 dx becomes [x[SUP]3[/SUP]/3 + 3x] 2 > Sub in the bounding values eg. x = 3... 9 + 9 = 18 x = 1... 1/3 + 3 = 3 1/3 3 > Take them away from each other eg. 18-3 1/3 = 14 2/3 And that's the area bounded by the curve and the X axis when 1 <= x <= 4[/QUOTE] while we're on the topic of integration [img]http://dl.dropbox.com/u/6624546/WAYWO_integrate.png[/img] kinda cool to fire up an old, forgotten project and have it do something :v: oh and here's from 1 to 4 [img]http://dl.dropbox.com/u/6624546/WAYWO_integrate2.png[/img]
I'm passing everything around by reference, but that isn't really working. Here's my code if you really want to know(currently crashes):[url]http://pastebin.com/KWgZudTH[/url] [editline]16th January 2012[/editline] [QUOTE=Darwin226;34242668]Interesting. I thought heuristics were bad for mazes.[/QUOTE] They are, A* get's beaten by a best first search, that took 2 seconds to solve.
[QUOTE=neos300;34242867]I'm passing everything around by reference, but that isn't really working. Here's my code if you really want to know(currently crashes):[url]http://pastebin.com/KWgZudTH[/url] [editline]16th January 2012[/editline] They are, A* get's beaten by a best first search, that took 2 seconds to solve.[/QUOTE] SetupScene() statically declares some Spheres and puts their addresses in a vector which is returned. The problem is that these Spheres fall out of scope once the function returns, making the addresses in the vector invalid. What you need to do is allocate these Sphere objects dynamically (Sphere *s1 = new Sphere(); // bla bla bla). This allows you to use those pointers without worrying about the objects falling out of scope. You must, however remember to free the memory using delete at the end of your program.
[QUOTE=neos300;34242867]I'm passing everything around by reference, but that isn't really working. Here's my code if you really want to know(currently crashes):[URL]http://pastebin.com/KWgZudTH[/URL] [editline]16th January 2012[/editline] They are, A* get's beaten by a best first search, that took 2 seconds to solve.[/QUOTE] I tried this and had to sort it out when porting my game to C++. If you want to pass around vector elements, you should really new() each element and make the vector one of pointers. With vectors of polymorphic classes, you have to use pointers otherwise you can only insert objects of the base type - well, you can try to add a derived object to the list but it'll slice the extra bit off and put it in as a base object. Instantiating objects then storing a ref to them in the vector will break once they go out of scope, and passing around references to objects in vectors (which aren't stored as pointers) will break if you do anything with the list when using the ref.
One thing I should have mentioned about returning references: [b]don't do it unless it's a member variable[/b]. std::vector<traceShape*> s gets deconstructed at the end of SetupScene, but the function still returns a reference to the (now deconstructed) vector. [editline]16th January 2012[/editline] [url]http://stackoverflow.com/questions/4643713/c-returning-reference-to-local-variable[/url] [editline]16th January 2012[/editline] In the case of SetupScene, just return the vector; not a reference.
Okay, thanks for the help. [editline]16th January 2012[/editline] It works, yay! Time to make boxes.
[QUOTE=KillerJaguar;34243042]One thing I should have mentioned about returning references: [b]don't do it unless it's a member variable[/b]. std::vector<traceShape*> s gets deconstructed at the end of SetupScene, but the function still returns a reference to the (now deconstructed) vector. [editline]16th January 2012[/editline] [url]http://stackoverflow.com/questions/4643713/c-returning-reference-to-local-variable[/url] [editline]16th January 2012[/editline] In the case of SetupScene, just return the vector; not a reference.[/QUOTE] True. Totally forgot that. Which brings up a rant (C++ has that effect on me far too often): Why is it fine and dandy to return something which is invalidated by exactly the act of returning. And in a related matter: Why on earth is there no sane way of having collections of statically allocated polymorphic objects?
[I]What are you working on?[/I] I'm working on an Animation component for my component system. It uses an AnimationContainer which loads a json file with the predefined animations which contains an array of frames which defines the position and the length of the frame. This makes it really easy for the graphics designer on our group to make spritesheets and animations belonging to that sheet because all he has to do is to make a json file with the same name as the spritesheet and voila. If the object has an animation component it can animate the frames in it(move the subrect). This makes it so that you don't have to have predefined positions in your spritesheets that are reserved for one animation. I'm also thinking of utilizing a binary tree for quick lookup of which animationcontainer belongs to what spritesheet, or a hashmap. But a normal map should work for now. [B]WAYWO WANTS SCREENSHOTS?[/B] [b]NO![/b] You're just gonna have to take my word for it. [I]This shit blows my mind and you don't even know it.[/I](it's not special)
[QUOTE=grlira;34243208]True. Totally forgot that. Which brings up a rant (C++ has that effect on me far too often): Why is it fine and dandy to return something which is invalidated by exactly the act of returning. And in a related matter: Why on earth is there no sane way of having collections of statically allocated polymorphic objects?[/QUOTE] For the first part, the program simply doing its job. A reference and a pointer are pretty much the same thing, the difference being one is easier to write with. Pointers (and references by extension) have no clue what address they're pointing to or what it is even about. When you derefence one, then it cares what the variable actually contains. The second part, I'm not quite sure what you mean. If your complaining about STL containers being inconvenient to use with pointers and references for polymorphic objects, it's just another way of how C++ works. With a statically allocated variable, the compiler knows exactly what member functions and variables it has. A polymorphic variable is more trouble to the compiler because then it perform additional lookups at run-time as opposed to at compile-time. It knows Base has a virtual (abstract) function Foo, but it doesn't know what to do. The program will have to, at run-time, determine what Foo does of all the derived classes of Base.
Well, I have no idea what I'm doing when it comes to planes and boxes. I got some plane collision code but I have no idea what to enter into it (it wants a normal and a 'd' - whatever that is)
[QUOTE=KillerJaguar;34243436]For the first part, the program simply doing its job. A reference and a pointer are pretty much the same thing, the difference being one is easier to write with. Pointers (and references by extension) have no clue what address they're pointing to or what it is even about. When you derefence one, then it cares what the variable actually contains. The second part, I'm not quite sure what you mean. If your complaining about STL containers being inconvenient to use with pointers and references for polymorphic objects, it's just another way of how C++ works. With a statically allocated variable, the compiler knows exactly what member functions and variables it has. A polymorphic variable is more trouble to the compiler because then it perform additional lookups at run-time as opposed to at compile-time. It knows Base has a virtual (abstract) function Foo, but it doesn't know what to do. The program will have to, at run-time, determine what Foo does of all the derived classes of Base.[/QUOTE] Yes I understand the technical aspects. I was just saying that it's annoying to have to deal with those details. What I meant in the second part is that if you want to place polymorphic objects in a container you need to store pointers instead of the objects themselves and if you are filling a container within a function, because of scope problems, you need to allocate the objects dynamically. I understand why you have to do it, but it's an annoying aspect of the language.
[QUOTE=grlira;34243663]Yes I understand the technical aspects. I was just saying that it's annoying to have to deal with those details. What I meant in the second part is that if you want to place polymorphic objects in a container you need to store pointers instead of the objects themselves and if you are filling a container within a function, because of scope problems, you need to allocate the objects dynamically. I understand why you have to do it, but it's an annoying aspect of the language.[/QUOTE] You get used to it after a while. It's a weird quirk, but overall I still love C++.
[img]http://28.media.tumblr.com/tumblr_lxwo1d1AAs1qa95i0o1_500.gif[/img] messing around with python and generative art, i hope i can make something mildly interesting come out of this
Anyone know any algorithms for doing ray intersection with boxes/cubes?
Speaking of animation and animation systems, it strikes me odd as to how pretty much every game since '96 has been using skeletal animations, and how little resources there are at times. There's lots of theory/abstraction (traverse your skeleton and build a transform matrix for each bone that's relative to it's parent, upload the matrixes to the GPU and multiple the vertexes by the matrix * boneWeight), but I can find very little implementation.
[QUOTE=Lord Ned;34244168]Speaking of animation and animation systems, it strikes me odd as to how pretty much every game since '96 has been using skeletal animations, and how little resources there are at times. There's lots of theory/abstraction (traverse your skeleton and build a transform matrix for each bone that's relative to it's parent, upload the matrixes to the GPU and multiple the vertexes by the matrix * boneWeight), but I can find very little implementation.[/QUOTE] Well honestly, it doesn't seem complicated at all. Why do you need an example? [editline]16th January 2012[/editline] Make a bone class that has a list of children and a parent. Have it's model matrix in the class but before passing it to the shader multiply it with the model matrix of it's parent. All that's left to do is ensure that you start by first rendering the bone without a parent, then its children, then their children and so on.
[QUOTE=child birth;34243961][img]http://28.media.tumblr.com/tumblr_lxwo1d1AAs1qa95i0o1_500.gif[/img] messing around with python and generative art, i hope i can make something mildly interesting come out of this[/QUOTE] I'm currently having heavy insomnia and this pattern fucks my brain up
This is so fucking irritating. You know when you drive home from work and you "wake up" in your driveway wondering if you actually drove there or teleported because you spaced out? Yeah it happens to me when I write code. Sometimes when I get into a nice programming flow and switch files in visual studio to implement something or look up something I space out because my brain switches to autopilot and I completely forget what the fuck I was doing 3 seconds ago or what I was supposed to do. A complete blackout. And I spend 10 seconds just staring at my screen, not doing anything at all. And I think "I should be doing something, but I forgot...what is it uhmm...maybe check my clipboard, oh I remember now".
[QUOTE=neos300;34244126]Anyone know any algorithms for doing ray intersection with boxes/cubes?[/QUOTE] This one is quite neat, although personally I found it slightly hard to follow: [url]http://www.siggraph.org/education/materials/HyperGraph/raytrace/rtinter3.htm[/url] Here is an implemented method in C#: [url]http://pastebin.com/KisLS90K[/url] Use at free will
[url=http://postimage.org/image/q8bokb32v/][img]http://s7.postimage.org/q8bokb32v/pic.jpg[/img][/url] Click for free cooties.
the grain on the tiles hurts my eyes. [editline]16th January 2012[/editline] just saying.
[QUOTE=sondre99v;34245143] Here is an implemented method in C#: [url]http://pastebin.com/KisLS90K[/url] Use at free will[/QUOTE] [cpp]public double? Intersects(BoundingBox boundingBox)[/cpp] Why is there a ?
he wasn't entirely confident? :v:
[QUOTE=ief014;34245913][cpp]public double? Intersects(BoundingBox boundingBox)[/cpp] Why is there a ?[/QUOTE] It means it can be null.
any type "T?" is just syntax sugar for [url=http://msdn.microsoft.com/en-us/library/b3h38hb0.aspx]Nullable<T>[/url]
That's interesting syntactic sugar. [editline]16th January 2012[/editline] Can't see why double would need to be nullable, though.
[QUOTE=esalaka;34246060]That's interesting syntactic sugar. [editline]16th January 2012[/editline] Can't see why double would need to be nullable, though.[/QUOTE] IMO maybe it's a bit too much. Seeing double? would be awesome if it JUST meant that it can be null. Unfortunately to do anything with the actual number you need to do num.Value and that usually turns out ugly. I would prefer if Nullable<double> was the only option. It kind of alerts the programmer (and anyone else reading his code) that there's going to be additional shit he has to deal with.
[QUOTE=esalaka;34246060]That's interesting syntactic sugar. [editline]16th January 2012[/editline] Can't see why double would need to be nullable, though.[/QUOTE] At a guess, if the double is null, there's no intersection, otherwise the intersection depth?
[QUOTE=danharibo;34246234]At a guess, if the double is null, there's no intersection, otherwise the intersection depth?[/QUOTE] Since the depth can't really be negative, is there really need for null?
-snip-
Sorry, you need to Log In to post a reply to this thread.