• What do you need help with? Version 5
    5,752 replies, posted
I'm having trouble with signaling the EOF in C using Command Prompt. I read in places that CTRL-Z is the end of file character, but it doesn't seem to be working for me. What am I doing wrong? [IMG]http://i.imgur.com/WWWSnRU.png[/IMG] [IMG]http://i.imgur.com/Yg9y6Pk.png[/IMG]
[QUOTE=W00tbeer1;39418886]I'm having trouble with signaling the EOF in C using Command Prompt. I read in places that CTRL-Z is the end of file character, but it doesn't seem to be working for me. What am I doing wrong? [/QUOTE]Sometimes it's Control-D I've found (I believe this was on Linux), and other times there might not be a reliable way to signal it - especially on Windows. [editline]30th January 2013[/editline] [QUOTE=Meatpuppet;39418816]C++ question: Say I wanted this struct MenuItem The reason for this is because I want to be able to highlight the outline of the menuitem. Or will I just need to create a duplicate function for the MenuItem class?[/QUOTE] I don't know a lot of C++-specific features; there might be a more elegant way to do it, but why not just make a superclass which both Text and Menu inherit from?
[QUOTE=account;39419068]Sometimes it's Control-D I've found (I believe this was on Linux), and other times there might not be a reliable way to signal it - especially on Windows. [editline]30th January 2013[/editline] I don't know a lot of C++-specific features; there might be a more elegant way to do it, but why not just make a superclass which both Text and Menu inherit from?[/QUOTE] Ah yeah CTRL-D doesn't work either. Is there some sort of UNIX shell emulator or something like that that I can download on Windows? I remember reading something like that in one of my textbooks but I forgot the name.
[QUOTE=W00tbeer1;39419156]Ah yeah CTRL-D doesn't work either. Is there some sort of UNIX shell emulator or something like that that I can download on Windows? I remember reading something like that in one of my textbooks but I forgot the name.[/QUOTE] Yeah, [url]http://www.mingw.org/[/url] is a pretty popular one.
[QUOTE=account;39419068]Sometimes it's Control-D I've found (I believe this was on Linux), and other times there might not be a reliable way to signal it - especially on Windows. [editline]30th January 2013[/editline] I don't know a lot of C++-specific features; there might be a more elegant way to do it, but why not just make a superclass which both Text and Menu inherit from?[/QUOTE] I think I'll just get rid of MenuItem altogether. [editline]31st January 2013[/editline] Ok here is my code now: Text.h [cpp] class Text { public: .... void Text::highlightRectOutline(sf::RenderWindow &window, sf::Color color); struct MenuItem { public: sf::IntRect buttonrect; Menu::MenuResult action; }; [/cpp] Menu.h [cpp]class Menu { public: static enum MenuResult { Exit, Options, Back, ChangeResolution, Play, Nothing }; MenuResult showMMenu(sf::RenderWindow &window); MenuResult showOMenu(sf::RenderWindow &window); private: MenuResult getMenuResponse(sf::RenderWindow &window); MenuResult handleClick(int x, int y); Menu::MenuResult Menu::handleButtonHover(sf::RenderWindow &window, Text::MenuItem menuItem, int x, int y); std::list<Text::MenuItem> menuItems; };[/cpp] How do I get MenuResult to be able to use the function highlightRectOutline()?
Hi ! I need help with VBOs : [CODE] void create_vbo() { glGenBuffers(2, buffer_id ); // vertices. glBindBuffer(GL_ARRAY_BUFFER, buffer_id[0]); glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW); // indexes glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, buffer_id[1]); glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indexes), indexes, GL_STATIC_DRAW); } void draw() { glEnable(GL_CULL_FACE); glCullFace(GL_BACK); glBindBuffer(GL_ARRAY_BUFFER, buffer_id[0]); glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_COLOR_ARRAY); glVertexPointer(3, GL_FLOAT, 7*sizeof(float), 0); glColorPointer(4, GL_FLOAT, 7*sizeof(float), (void*)(3*sizeof(float))); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, buffer_id[1]); glDrawElements(GL_TRIANGLES, 36, GL_UNSIGNED_INT, 0); glDisableClientState(GL_COLOR_ARRAY); glDisableClientState(GL_VERTEX_ARRAY); } [/CODE] The thing I don't understand in this code is why is he not binding buffer_id[0] before glDrawElements(). How does glDrawElements() knows what are the vertices if we're only using the indexes ?
glDrawElements takes an index and uses it to do pointer math on the currently bound VBO using the current glVertexPointer/glColorPointer information. Specifically, it does this: *(vbo + (index * stride) + offset), where "vbo" is a pointer to the VBO somewhere in VRAM, "index" is the index that's read from the VBO bound to GL_ELEMENT_ARRAY_BUFFER, "stride" is the stride parameter of gl[Vertex/Color/etc]Pointer, and "offset" is the last parameter. The last parameter is technically a GLvoid* to provide backwards-compatibility for passing your vertex data instead of storing them in a VBO. So, for example, if you have index 12, it will look into the current VBO with something like this for the vertex position: *(vbo + (12 * (7 * sizeof(float)) + 0) and it will take 12 bytes (3 * GL_FLOAT). The vertex color will look like this: *(vbo + (12 * (7 * sizeof(float)) + 3 * sizeof(float)) and it will take 16 bytes (4 * GL_FLOAT).
I'm trying to split a list of tuples into just a list like [(1,2), (2,3),(3,4)] -> [1,2,2,3,3,4] I can do [[1,2], [2,3], [3,4]] by doing [[x, y] for (x, y) in tuple_list] but I'm unsure of how to split it completely like that. Tried [x, y for (x, y) in tuple_list] as well as [x for (x, x)...] I could do this the wrong way easily (convert to [x, y] then split it or something) but surely there's a syntax where I can just do it in once step. In this case the order isn't important, so I can just do list = [x for (x, y)...] + [y for (x,y)...] but I would like to understand the syntax of these list comprehensions a bit better. [editline]31st January 2013[/editline] python fyi
I'd really like to know what is the method with "?" and ":" in Java used for and how to use it in your favour
[QUOTE=RandomDexter;39426131]I'd really like to know what is the method with "?" and ":" in Java used for and how to use it in your favour[/QUOTE] if you mean this: [code]int i = x<5 ? 1 : 2;[/code] its effectively the same as: [code]int i; if(x < 5) i = 1; else i = 2; [/code] the way its used is: (conditional) ? true statement : false statement; the only use it has is to make your code shorter
[QUOTE=Richy19;39426214]if you mean this: [code]int i = x<5 ? 1 : 2;[/code] its effectively the same as: [code]int i; if(x < 5) i = 1; else i = 2; [/code] the way its used is: (conditional) ? true statement : false statement; the only use it has is to make your code shorter[/QUOTE] That's it, thanks
Regarding the conditional operator (that's the [I]?:[/I] operator's name), I use it extensively and I honestly find it very useful. Some people, on the other hand, despise it and say that it makes your code less readable. Either way, I recommend you try to use it as much as you can in your code (only where it makes sense, of course) and decide for yourself. What I [U]don't[/U] recommend, however, is nesting multiple conditional statements together; in such cases, use if/else blocks instead.
I think the best feature about is that it's an expression so it saves you from redundant typing and can be used almost anywhere.
[QUOTE=Mozartkugeln;39427619]What I [U]don't[/U] recommend, however, is nesting multiple conditional statements together; in such cases, uses if/else blocks instead[/QUOTE] IMO I think it looks way better than a million if/else blocks [cpp] char grade = ( p>=80 ? 'A' : p>=70 ? 'B' : p>=60 ? 'C' : p>=50 ? 'D' : 'F' ); [/cpp] [cpp] char grade; if (p>=80) grade = 'A'; else if (p>=70) grade = 'B'; else if (p>=60) grade = 'C'; else if (p>=50) grade = 'D'; else grade = 'F'; [/cpp]
[QUOTE=ief014;39427668]IMO I think it looks way better than a million if/else blocks [cpp] char grade = ( p>=80 ? 'A' : p>=70 ? 'B' : p>=60 ? 'C' : p>=50 ? 'D' : 'F' ); [/cpp] [cpp] char grade; if (p>=80) grade = 'A'; else if (p>=70) grade = 'B'; else if (p>=60) grade = 'C'; else if (p>=50) grade = 'D'; else grade = 'F'; [/cpp][/QUOTE] In specific scenarios like this it could be cleaner. In general use if/else blocks primarily and the ternary operator when it makes code look cleaner.
[QUOTE=ief014;39427668]IMO I think it looks way better than a million if/else blocks [cpp] char grade = ( p>=80 ? 'A' : p>=70 ? 'B' : p>=60 ? 'C' : p>=50 ? 'D' : 'F' ); [/cpp] [cpp] char grade; if (p>=80) grade = 'A'; else if (p>=70) grade = 'B'; else if (p>=60) grade = 'C'; else if (p>=50) grade = 'D'; else grade = 'F'; [/cpp][/QUOTE] It may look better, but I find it harder to understand at a glance.
[QUOTE=ArgvCompany;39427807]It may look better, but I find it harder to understand at a glance.[/QUOTE] This is exactly the reason why I prefer vertical stacking rather than nesting conditional statements horizontally.
Ok, my homework goes like this, the user inserts three numeral between 1 and 9, for example 2 4 3. The output of the program should look like this [code] 22 4444 333 22 4444 333 4444 333 4444 [/code] I wrote a piece of shit and i keep getting infinite loop. What am i doing wrong and how could i write this more efficient and less time consuming, keep in mind that i am a mere beginner thou [code] import java.util.Scanner; public class IgorjeviBloki{ public static void main(String[] args){ Scanner scan = new Scanner(System.in); System.out.print("Vnesite prvo stevko: "); int first=scan.nextInt(); System.out.print("Vnesite drugo stevko: "); int second=scan.nextInt(); System.out.print("Vnesite tretjo stevko: "); int third=scan.nextInt(); int firstblock=(int)Math.pow(first,2); int secondblock=(int)Math.pow(second,2); int thirdblock=(int)Math.pow(third,2); while(0<firstblock || 0<secondblock || 0<thirdblock) { printAline(firstblock,secondblock,thirdblock,first,second,third); } } public static void printAline(int firstblock, int secondblock, int thirdblock, int first, int second, int third){ if(0<firstblock){ for(int i=0;i<first;i++){ System.out.print(first); } System.out.print(" "); firstblock=firstblock-first; } else{ for(int j=0;j<first+1;j++){ System.out.print(" "); } } if(0<secondblock){ for(int i=0;i<second;i++){ System.out.print(second); } System.out.print(" "); secondblock=secondblock-second; } else{ for(int j=0;j<second+1;j++){ System.out.print(" "); } } if(0<thirdblock){ for(int i=0;i<third;i++){ System.out.print(third); } System.out.println(); thirdblock=thirdblock-third; } else{ System.out.println(); } } } [/code]
[QUOTE=RandomDexter;39428118][code] while(0<firstblock || 0<secondblock || 0<thirdblock) { printAline(firstblock,secondblock,thirdblock,first,second,third); } [/code][/QUOTE] This will never terminate as long as one of the three variables is > 0 at the start.
[QUOTE=account;39428172]This will never terminate as long as one of the three variables is > 0 at the start.[/QUOTE] but the first/second/third block should be decreasing [QUOTE]firstblock=firstblock-first;[/QUOTE]
Crosspost from WAYWO. [IMG]http://i.minus.com/iNp7X4yHOvWId.png[/IMG] Got the lighting not being totally broken (is now just from the control point) and also fixed needing to disable backface culling. Another issue has however come to my attention and I am perplexed. In the screenshot shown the green circled bit is what should be generated, the beams in red should not. From what I can tell they are between the control points, at least approximately, since level 1 tessellation (eg none) results in them disappearing. My code can be found at [url]http://pastebin.com/0P0s2uP0[/url] in case anyone has any ideas.
[QUOTE=Meatpuppet;39419414]I think I'll just get rid of MenuItem altogether. [editline]31st January 2013[/editline] Ok here is my code now: Text.h [cpp] class Text { public: .... void Text::highlightRectOutline(sf::RenderWindow &window, sf::Color color); struct MenuItem { public: sf::IntRect buttonrect; Menu::MenuResult action; }; [/cpp] Menu.h [cpp]class Menu { public: static enum MenuResult { Exit, Options, Back, ChangeResolution, Play, Nothing }; MenuResult showMMenu(sf::RenderWindow &window); MenuResult showOMenu(sf::RenderWindow &window); private: MenuResult getMenuResponse(sf::RenderWindow &window); MenuResult handleClick(int x, int y); Menu::MenuResult Menu::handleButtonHover(sf::RenderWindow &window, Text::MenuItem menuItem, int x, int y); std::list<Text::MenuItem> menuItems; };[/cpp] How do I get MenuResult to be able to use the function highlightRectOutline()?[/QUOTE] anyone?
[QUOTE=ArgvCompany;39427807]It may look better, but I find it harder to understand at a glance.[/QUOTE] I've used them a bunch that it's just like reading a chain of if/elseifs. But that's just me
Im trying to setup SFML.Net on mono, I have built everything ok but trying one of the examples has this: [code] Unhandled Exception: System.DllNotFoundException: libcsfml-graphics.so at (wrapper managed-to-native) SFML.Graphics.RenderWindow:sfRenderWindow_create (SFML.Window.VideoMode,string,SFML.Window.Styles,SFML.Window.ContextSettings&) at SFML.Graphics.RenderWindow..ctor (VideoMode mode, System.String title, Styles style, ContextSettings settings) [0x00000] in <filename unknown>:0 at SFML.Graphics.RenderWindow..ctor (VideoMode mode, System.String title) [0x00000] in <filename unknown>:0 at shader.Program.Main () [0x00000] in <filename unknown>:0 [ERROR] FATAL UNHANDLED EXCEPTION: System.DllNotFoundException: libcsfml-graphics.so at (wrapper managed-to-native) SFML.Graphics.RenderWindow:sfRenderWindow_create (SFML.Window.VideoMode,string,SFML.Window.Styles,SFML.Window.ContextSettings&) at SFML.Graphics.RenderWindow..ctor (VideoMode mode, System.String title, Styles style, ContextSettings settings) [0x00000] in <filename unknown>:0 at SFML.Graphics.RenderWindow..ctor (VideoMode mode, System.String title) [0x00000] in <filename unknown>:0 at shader.Program.Main () [0x00000] in <filename unknown>:0 The application was terminated by a signal: SIGHUP [/code] Im using the sfmlnet-audio-2.dll.config files to remap the windows fdll's to linux .so as so: [code] <?xml version="1.0" encoding="utf-8"?> <configuration> <dllmap dll="csfml-audio-2" target="libcsfml-audio.so" /> </configuration> <?xml version="1.0" encoding="utf-8"?> <configuration> <dllmap dll="csfml-graphics-2" target="libcsfml-graphics.so" /> </configuration> <?xml version="1.0" encoding="utf-8"?> <configuration> <dllmap dll="csfml-window-2" target="libcsfml-window.so" /> </configuration>[/code] and the csfml files are in usr/local/lib: [code] richy@linux-nc18:/usr/local/lib> ls Box2D libcsfml-network.so.2 libsfml-audio-d.so.2.0 libsfml-network.so.2 libBox2D.a libcsfml-network.so.2.0 libsfml-audio-s.a libsfml-network.so.2.0 libBox2D.so libcsfml-system-d.so libsfml-audio-s-d.a libsfml-system-d.so libBox2D.so.2.1.0 libcsfml-system-d.so.2 libsfml-audio.so libsfml-system-d.so.2 libBulletCollision.a libcsfml-system-d.so.2.0 libsfml-audio.so.1.6 libsfml-system-d.so.2.0 libBulletDynamics.a libcsfml-system.so libsfml-audio.so.2 libsfml-system-s.a libBulletSoftBody.a libcsfml-system.so.2 libsfml-audio.so.2.0 libsfml-system-s-d.a libcsfml-audio-d.so libcsfml-system.so.2.0 libsfml-graphics-d.so libsfml-system.so libcsfml-audio-d.so.2 libcsfml-window-d.so libsfml-graphics-d.so.2 libsfml-system.so.1.6 libcsfml-audio-d.so.2.0 libcsfml-window-d.so.2 libsfml-graphics-d.so.2.0 libsfml-system.so.2 libcsfml-audio.so libcsfml-window-d.so.2.0 libsfml-graphics-s.a libsfml-system.so.2.0 libcsfml-audio.so.2 libcsfml-window.so libsfml-graphics-s-d.a libsfml-window-d.so libcsfml-audio.so.2.0 libcsfml-window.so.2 libsfml-graphics.so libsfml-window-d.so.2 libcsfml-graphics-d.so libcsfml-window.so.2.0 libsfml-graphics.so.1.6 libsfml-window-d.so.2.0 libcsfml-graphics-d.so.2 libglfw.a libsfml-graphics.so.2 libsfml-window-s.a libcsfml-graphics-d.so.2.0 libglfw.so libsfml-graphics.so.2.0 libsfml-window-s-d.a libcsfml-graphics.so libLinearMath.a libsfml-network-d.so libsfml-window.so libcsfml-graphics.so.2 libluajit-5.1.a libsfml-network-d.so.2 libsfml-window.so.1.6 libcsfml-graphics.so.2.0 libluajit-5.1.so libsfml-network-d.so.2.0 libsfml-window.so.2 libcsfml-network-d.so libluajit-5.1.so.2 libsfml-network-s.a libsfml-window.so.2.0 libcsfml-network-d.so.2 libluajit-5.1.so.2.0.0 libsfml-network-s-d.a lua libcsfml-network-d.so.2.0 libsfml-audio-d.so libsfml-network.so pkgconfig libcsfml-network.so libsfml-audio-d.so.2 libsfml-network.so.1.6 [/code] Anyone know whats going on?
[QUOTE=account;39413758]Java would also be a good option since it's cross platform and more strictly object-oriented, which I feel helps keep the code pure.[/QUOTE] But "pure" code isn't any better. Actually it's a pretty meaningless term. Sure, it pleases the university chucklefucks who never touch a line of code, but in real life you want what's appropriate for the problem at hand, not be forced to turn every screw into a nail so that your neat hammer can push it in.
Having a little trouble with operator overloading in C++ [IMG]https://dl.dropbox.com/u/6769272/screenshots/quat_error_cpp.png[/IMG] For some reason I can't call the reciprocal method on the quaternion object that's passed by reference - here's the source code for Quaternion.reciprocal() : [code]// Reciprocal of quaternion q Quaternion Quaternion::reciprocal() { return this->conjugate() / pow( this->norm(), 2 ); }[/code] [editline]1st February 2013[/editline] Woops, silly mistake - fixed it!
[QUOTE=Falcqn;39433787]Having a little trouble with operator overloading in C++ [IMG]https://dl.dropbox.com/u/6769272/screenshots/quat_error_cpp.png[/IMG] For some reason I can't call the reciprocal method on the quaternion object that's passed by reference - here's the source code for Quaternion.reciprocal() : [code]// Reciprocal of quaternion q Quaternion Quaternion::reciprocal() { return this->conjugate() / pow( this->norm(), 2 ); }[/code] [editline]1st February 2013[/editline] Woops, silly mistake - fixed it![/QUOTE] If anyone's run into the same problem, it's usually because "that" in this context has the const modifier attached to it which means that it is not allowed to be modified. The method reciprocal does not have the const modifier which means that it makes no promises about whether the object is going to be modified by calling that function. Calling the mutable method of a const object is not allowed, causing this error.
[QUOTE=ief014;39427668]char grade = ( p>=80 ? 'A' : p>=70 ? 'B' : p>=60 ? 'C' : p>=50 ? 'D' : 'F' ); [/QUOTE] What about this? [code] const char grades[] = "FFFFFDCBAAA"; char grade = grades[p / 10]; [/code]
[QUOTE=SiPlus;39435342]What about this? [code] const char grades[] = "FFFFFDCBAAA"; char grade = grades[p / 10]; [/code][/QUOTE] I like this solution.
Anyone here got some experience with Kendo UI? I'm having some trouble with elements that need a datasource, when I set it to an object that I added to the model all elements needing datasource will behave as simple textboxes and if I set it to a local array as an example they just behave as if no datasource was set at all. Using it with Spring
Sorry, you need to Log In to post a reply to this thread.