• What do you need help with? V. 3.0
    4,884 replies, posted
[QUOTE=Box Eater;32406533]In C++, if I were to create and initialise two arrays one after the other, why does the second array get addresses allocated earlier than first one?[/QUOTE] Because why not?
[QUOTE=Jookia;32403943]Is there a way to simplify this with a loop? Compile-time is fine, I just don't want to do it this way. -code snip-[/QUOTE] [cpp] #include <cstdio> using std::printf; enum { TEST_UTF32, TEST_UTF16, TEST_UTF8 }; template<typename T> void testUnicode(size_t i) { testUTF<T, uint32_t>(&testEncs[i], &testEncs[0]); testUTF<T, uint16_t>(&testEncs[i], &testEncs[1]); testUTF<T, uint8_t> (&testEncs[i], &testEncs[2]); } int main(void) { printf("Testing UTF-32...\n"); testUnicode<uint32_t>(TEST_UTF32); printf("Testing UTF-16...\n"); testUnicode<uint16_t>(TEST_UTF16); printf("Testing UTF-8...\n"); testUnicode<uint8_t>(TEST_UTF8); printf("All tests passed.\n"); return 0; } [/cpp] It is possible to do this in a loop, and it is possible to automatically map the index to the type, but it's not even close to being worth it in this simple case.
[QUOTE=Jookia;32406608]In Python 2.7 how would I make a Unicode string? I mean, I can load the same string from a file, but it's just one line.[/QUOTE] Given an object of type "str", call "unicode" on it. If a string literal is being used, use the "u" prefix, i.e., [code]u"This is literally the worst thing ever"[/code] Python 2.x's unicode support is utter shit, and a PITA (and while externally it [b]might[/b] be UTF-8, internally everything is UTF-16, or UTF-32, depending on what version you are using and not, surprisingly which platform you are on!). It's even worse if you need to write a wrapper in C/C++, (even Cython can't abstract that shit!) They fixed it with Python 3 however, so that all strings are treated as UTF-8 (although internally they may be stored as UTF-16, or UTF-32, however it *does* actually depend on the platform in that case. Note, however, that on OS X, Cocoa's NSString is a UTF-16 string, while wchar_t* is UTF-32. Python 3 goes with the former IIRC, however everything printed out is treated as UTF-8 so it doesn't really matter :v: THE MORE YOU KNOW --==*
I can't find any information on how to properly assign IPEndpoints when using UDP sockets to communicate... All the examples/literature I've found use communication on localhost in their examples, yet when i try and use my routers global IP with udp port forwarding setup it doesn't receive the packet. Anyone know what I should be reading?
I don't know if I'm missing something here, but can anybody tell me what the hell is this particular snippet of code doing? (If necessary give order the value 4, it's an int) [cpp] float *temp = new float[(order-1)*(order-1)]; float **minor = new float*[order-1]; for(int i=0;i<order-1;i++) minor[i] = temp+(i*(order-1));[/cpp] The part I don't get is how temp, an array (?) is being summed to (i*(order-1)), which is an int. I need to know this to complete my conversion of some matrix inversion code to Lua. Thanks in advance.
[QUOTE=Asgard;32406756]You mean multidimensional or just multiple arrays?[/QUOTE] Multiple arrays
Im trying to make a sprite invisible in XNA but it doesn't disappear completelly, it just goes partially transparent. Im doing this: in update [code]if (Keyboard.GetState().IsKeyDown(Keys.Right)) { textCol.A -= (byte)(gameTime.ElapsedGameTime.TotalMilliseconds / 10); textCol.A = 0; Console.WriteLine(textCol.A); }[/code] in draw [code]spriteBatch.Begin(); spriteBatch.Draw(texture, new Rectangle(100,100,200,200), textCol); spriteBatch.End();[/code] textCol.Alpha reaches 0 but it only goes semi transparent Turns out i need to shrink RGBA not just Alpha
[QUOTE=Big Bang;32410702]I don't know if I'm missing something here, but can anybody tell me what the hell is this particular snippet of code doing? (If necessary give order the value 4, it's an int) [cpp] float *temp = new float[(order-1)*(order-1)]; float **minor = new float*[order-1]; for(int i=0;i<order-1;i++) minor[i] = temp+(i*(order-1));[/cpp] The part I don't get is how temp, an array (?) is being summed to (i*(order-1)), which is an int. I need to know this to complete my conversion of some matrix inversion code to Lua. Thanks in advance.[/QUOTE] Remember that temp is a pointer, not some integer or float variable. Doing temp+x means adding x to the address; *temp would access the first float, *(temp + 1) the second and so on. minor is a vector of pointers to that temp array, specifically to every (order-1)th float* in temp. Might not be that understandable with words, draw a picture of it.
I'm using the crap but useful language VB.net I'm trying to make multiple folder while using check boxes. So check said boxes, press a button and it takes the names from each checkbox to create a folder in a directory. Yet, I have no idea on how to do it.
[QUOTE=Lerlth;32416229]I'm using the crap but useful language VB.net I'm trying to make multiple folder while using check boxes. So check said boxes, press a button and it takes the names from each checkbox to create a folder in a directory. Yet, I have no idea on how to do it.[/QUOTE] Upon the button press, you could either: 1) Have lots of "If Checkbox1.Checked Then System.IO.Directory.Create("Folder1")" 2) Have an array of all checkboxes, and loop through them.
Does anyone know whats wrong here? [code]spriteBatch.Begin(); spriteBatch.Draw(texture, new Rectangle(100,100,300,200), null,Color.White,0.0f,Vector2.Zero, SpriteEffects.None, 0.25f); spriteBatch.Draw(texture, new Rectangle(200, 150, 300, 200),null, textCol ,0.0f, Vector2.Zero, SpriteEffects.None, depth); spriteBatch.Draw(texture, new Rectangle(300, 200, 300, 200), null,Color.White,0.0f,Vector2.Zero, SpriteEffects.None, 0.75f); spriteBatch.End();[/code] depth changes when I press up/down but the order there drawn on wont change
For a Java assignment, I'm faced with the following: I have an array with 26 places. Using a for loop, I have to allocate a letter of the alphabet to each spot in the array. I have my array declared and all the letters declared as a single char and that's it. Stumped, clueless, baffled, double-you-tee-effing as to how to continue. Who can help?
[QUOTE=Richy19;32418524]Does anyone know whats wrong here? [code]spriteBatch.Begin(); spriteBatch.Draw(texture, new Rectangle(100,100,300,200), null,Color.White,0.0f,Vector2.Zero, SpriteEffects.None, 0.25f); spriteBatch.Draw(texture, new Rectangle(200, 150, 300, 200),null, textCol ,0.0f, Vector2.Zero, SpriteEffects.None, depth); spriteBatch.Draw(texture, new Rectangle(300, 200, 300, 200), null,Color.White,0.0f,Vector2.Zero, SpriteEffects.None, 0.75f); spriteBatch.End();[/code] depth changes when I press up/down but the order there drawn on wont change[/QUOTE] [url]http://msdn.microsoft.com/en-us/library/ff433698.aspx[/url]
[QUOTE=Sir Whoopsalot;32422353]For a Java assignment, I'm faced with the following: I have an array with 26 places. Using a for loop, I have to allocate a letter of the alphabet to each spot in the array. I have my array declared and all the letters declared as a single char and that's it. Stumped, clueless, baffled, double-you-tee-effing as to how to continue. Who can help?[/QUOTE] The assignment is probably about treating characters as integers. In Java, the "char" primitive type is a 16-bit integer containing a UTF-16 code unit. For example, the letter 'A' is represented by the value 65, 'B' is at 66, 'C' is at 67; it goes all the way up to 'Z' at 90. As char's are integers, you can do arithmetic on them: the expression 'A' + 2 promotes 'A' (of type char) to an int with the value 65, and the result of the expression is thus 67 (of type int). Cast that back to char and you have the character 'C'. That should be enough information for you to complete the assignment.
im trying to do my first major flash project, and i want to implement the [URL="http://code.google.com/p/collisiondetectionkit/"]collisiondetectionkit[/URL] to handle collisions in my game, but i dont know how to use classes. i know im asking a gigantic noob question but can someone please help?
[QUOTE=jA_cOp;32422492]The problem is probably about treating characters as integers: -code-[/QUOTE] Shouldn't you be explaining the general idea rather than giving him complete code for an assignment?
[QUOTE=ROBO_DONUT;32423229]Shouldn't you be explaining the general idea rather than giving him complete code for an assignment?[/QUOTE] Yes, you are completely right. I think I lost my train of thought as I was firing up Eclipse to figure out how the correct solution would look like in Java (as I don't do Java very often). I'll replace my post with an explanation - the code was wholly unnecessary.
Whoa. Chars are 16-bits in Java? I guess it's a good thing the semantics of Java are so different from C/C++ because I totally would've assumed they were 8-bits and done some pretty stupid stuff.
[QUOTE=ROBO_DONUT;32424334]Whoa. Chars are 16-bits in Java? I guess it's a good thing the semantics of Java are so different from C/C++ because I totally would've assumed they were 8-bits and done some pretty stupid stuff.[/QUOTE] Java does have the "byte" primitive for 8-bit integers, but remember that Java is a language without unsigned integers too. Attempting any kind of low-level operation in Java is not really encouraged by the language.
[QUOTE=jA_cOp;32424411]Java does have the "byte" primitive for 8-bit integers, but remember that Java is a language without unsigned integers too. Attempting any kind of low-level operation in Java is not really encouraged by the language.[/QUOTE] Such as [B]using the equality operator[/B]. Seriously.
Is there any good editor that works like MS Word, but has syntax highlighting? I was thinking like Latex with the listings package. I have to print it too,
[QUOTE=Swebonny;32427933]Is there any good editor that works like MS Word, but has syntax highlighting? I was thinking like Latex with the listings package. I have to print it too,[/QUOTE] For printing? You can't go wrong with LaTeX + Listings :v:
[code]FibOne(x) set A to 1 set B to 1 set Y to 2 while(X > Y) do set C to A + B set B to A set A to C set Y to Y + 1 return A end[/code] [code]FibTwo(x) if(X = 1) then set A to 1 else if(X = 2) then set A to 1 else set A to FibTwo(X-1) + FibTwo(X-2) return A end[/code] Would it be safe to say that FibOne would have a time complexity of O(n) and FibTwo O(log n)? FibTwo does a way lesser amount of operations as it is able to call itself, making X a smaller value and therefore cutting the amount of time it takes...?
[QUOTE=Chrispy_645;32428938][code]FibOne(x) set A to 1 set B to 1 set Y to 2 while(X > Y) do set C to A + B set B to A set A to C set Y to Y + 1 return A end[/code] [code]FibTwo(x) if(X = 1) then set A to 1 else if(X = 2) then set A to 1 else set A to FibTwo(X-1) + FibTwo(X-2) return A end[/code] Would it be safe to say that FibOne would have a time complexity of O(n) and FibTwo O(log n)? FibTwo does a way lesser amount of operations as it is able to call itself, making X a smaller value and therefore cutting the amount of time it takes...?[/QUOTE] Absolutely not! I'm guessing this is for an assignment of some sort. Think about it very carefully and you'll understand why that's wrong. Hint: Each time you call FibTwo, how many times does it call itself? What is the termination condition for this recursive function?
Nah it's not an assignment, although this is all self-teaching and practice for an exam. I'll have another go. :smile: I'm assuming you're referring to the time complexities being wrong, by the way?
[QUOTE=Chrispy_645;32429078]Nah it's not an assignment, although this is all self-teaching and practice for an exam. I'll have another go. :smile: I'm assuming you're referring to the time complexities being wrong, by the way?[/QUOTE] Yes. If this is not for an assignment, then I can give you the answer. I'm pretty sure FibTwo has exponential time complexity. Each time you call it, it calls itself twice to compute the two previous numbers. So if you do: FibTwo(n), it does: FibTwo(n-1) + FibTwo(n-2) (FibTwo(n-2) + FibTwo(n-3)) + (FibTwo(n-3) + FibTwo(n-4)) ...and so on.
Awesome - that's just what I thought - as for each X value which isn't 1 or 2, it is calling itself twice. I did some debugging again just to see how many times it called itself and for input X = 10 it was around about 50 times. No freaking idea why I thought that FibTwo did less operations to get the same answer though. =/
In my game I want to draw a black circle cutout over the scene. So inside the circle the scene should be drawn. Outside the circles radius the screen (or rendertarget) should be black. I'd like not to "cheat" this effect with an image. So can someone show me how to do a shader that does this? For clarification look at this: [url]http://youtu.be/IoZGi03aag8?t=2m45s[/url] (sorry for the lame example, couldn't find a better one)
Alright, I'm working on a game using Ogre3D and Newton Physics. In the game you can roll a ball around, and I had that working perfectly fine. However, I wanted to re-program it so you could use WASD to push the ball around no matter what angle the camera is on. However, I ran into a little problem. I can push the ball forward and back just fine, using these: [quote=Source]SetNewtonBodyForce(body_id, GetX() * bPushForce, GetY() * bPushForce, GetZ() * 0);[/quote] [quote=Source]SetNewtonBodyForce(body_id, -(GetX() * bPushForce), -(GetY() * bPushForce), GetZ() * 0);[/quote] However, I can't figure out how to push it left or right. For pushing it left, I tried this: [quote=Source]SetNewtonBodyForce(body_id, (GetX()-0.32) * bPushForce, (GetY()-0.32) * bPushForce, GetZ() * 0);[/quote] It works fine when the camera is pointing forward, but if I turn the camera, it just start going random directions. Also, to explain the 0.32ses: that's equivalent for 90 degrees in camera rotation when using the GetX/Y/Z command. So, do you guys have any ideas on how to make this work?
The actual formula would be [cpp]SetNewtonBodyForce(body_id, (GetX() * cos(theta) - GetY() * -sin(theta)) * bPushForce, (GetX() * sin(theta) + GetY() * cos(theta)) * bPushForce, GetZ() * 0);[/cpp] Since theta is 90°, cos(theta) is 0 and sin(theta) is 1, so [cpp]SetNewtonBodyForce(body_id, -GetY() * bPushForce, GetX() * bPushForce, GetZ() * 0);[/cpp]
Sorry, you need to Log In to post a reply to this thread.