1. Post #2641
    Meatpuppet's Avatar
    July 2010
    6,696 Posts
    How do you link Freetype with code blocks? I've googled it.
    Reply With Quote Edit / Delete Windows 7 United States Show Events

  2. Post #2642
    Guru mediation error
    Amiga OS's Avatar
    July 2012
    6,436 Posts
    I've just started teaching myself C. I'm having some issues with ANSI escape sequences.
    I want to move the cursor position, and the sequence to do this pretty much looks like this
    Code:
    printf("\033[6;3H");
    How would I inject a variable into the escape sequence without breaking it?
    I've tried
    Code:
    printf("\033[%s;%sH",y,x);
    but it doesn't work.
    Reply With Quote Edit / Delete Windows 8 United Kingdom Show Events

  3. Post #2643
    Gold Member
    esalaka's Avatar
    July 2007
    10,069 Posts
    How do you link Freetype with code blocks? I've googled it.
    Add freetype2 to the libraries
    Reply With Quote Edit / Delete Linux Finland Show Events

  4. Post #2644
    calzoneman's Avatar
    February 2008
    460 Posts
    I've just started teaching myself C. I'm having some issues with ANSI escape sequences.
    I want to move the cursor position, and the sequence to do this pretty much looks like this
    Code:
    printf("\033[6;3H");
    How would I inject a variable into the escape sequence without breaking it?
    I've tried
    Code:
    printf("\033[%s;%sH",y,x);
    but it doesn't work.
    First problem: Are the y and x variables strings? The %s format specifier tells printf to expect a C-string (char*), so if you pass y and x as integers, for example, you'll get weird results if not segfaults. If you want to printf an integer, use the format specifier %d.

    Second problem: The sequence "\0" in the context of a string literal in C will insert the NUL character which just so happens to also be the "end of string" flag for C strings. This means that printf("\0 ...") where ... can be anything results in printing nothing. If you want to literally output "\0", you have to escape the backslash:
    printf("\\033[%d;%dH", y, x);
    
    Reply With Quote Edit / Delete Windows 7 United States Show Events Agree Agree x 1Winner Winner x 1 (list)

  5. Post #2645
    Guru mediation error
    Amiga OS's Avatar
    July 2012
    6,436 Posts
    First problem: Are the y and x variables strings? The %s format specifier tells printf to expect a C-string (char*), so if you pass y and x as integers, for example, you'll get weird results if not segfaults. If you want to printf an integer, use the format specifier %d.

    Second problem: The sequence "\0" in the context of a string literal in C will insert the NUL character which just so happens to also be the "end of string" flag for C strings. This means that printf("\0 ...") where ... can be anything results in printing nothing. If you want to literally output "\0", you have to escape the backslash:
    printf("\\033[%d;%dH", y, x);
    
    Thanks a lot. I probably should have read a book before I dove in head first but I think I'm getting to grips with it.

    Edited:

    I'm used to languages like PHP and Javascript that don't give a shit what format your variables are in, they do it all for you.
    Reply With Quote Edit / Delete Windows 8 United Kingdom Show Events

  6. Post #2646
    Meatpuppet's Avatar
    July 2010
    6,696 Posts
    Add freetype2 to the libraries
    It can't find it.
    Reply With Quote Edit / Delete Windows 7 United States Show Events

  7. Post #2647
    Guru mediation error
    Amiga OS's Avatar
    July 2012
    6,436 Posts


    Whoops

    Code:
    void movecur(int x, int y)
    {
    	printf("\\033[%d;%dH", y, x);
    }
    Reply With Quote Edit / Delete Windows 8 United Kingdom Show Events Funny Funny x 2 (list)

  8. Post #2648
    Gold Member
    esalaka's Avatar
    July 2007
    10,069 Posts
    It can't find it.
    Well, where'd you put it on your HDD?
    Reply With Quote Edit / Delete Linux Finland Show Events

  9. Post #2649
    Gold Member
    Jookia's Avatar
    July 2007
    6,768 Posts
    It can't find it.
    Stop programming in Windows if you want to use external libraries. Everything's instantly easier in Linux.

    I love to bash Windows for heaps of things, and most of it is just me being bad at using Windows, but they just don't have a centralized way of managing third party libraries like Linux does, and I don't think they will any time soon.

    I think it inadvertently leads to reinventing the wheel.
    Reply With Quote Edit / Delete Linux Australia Show Events Agree Agree x 3 (list)

  10. Post #2650
    ECrownofFire's Avatar
    January 2011
    1,971 Posts
    Stop programming in Windows if you want to use external libraries. Everything's instantly easier in Linux.

    I love to bash Windows for heaps of things, and most of it is just me being bad at using Windows, but they just don't have a centralized way of managing third party libraries like Linux does, and I don't think they will any time soon.

    I think it inadvertently leads to reinventing the wheel.
    It's not so bad, really. Mingw and MSYS can deal with libraries without that big of a hassle. Still a pain in the ass compared to Linux, of course...
    Reply With Quote Edit / Delete Windows XP United States Show Events

  11. Post #2651
    Meatpuppet's Avatar
    July 2010
    6,696 Posts
    Stop programming in Windows if you want to use external libraries. Everything's instantly easier in Linux.

    I love to bash Windows for heaps of things, and most of it is just me being bad at using Windows, but they just don't have a centralized way of managing third party libraries like Linux does, and I don't think they will any time soon.

    I think it inadvertently leads to reinventing the wheel.
    You have no idea how much I want Linux. But I'm using my dad's pc and he gets all pissy about it even when I mention it to him.
    Reply With Quote Edit / Delete Windows 7 United States Show Events

  12. Post #2652
    An airbag saved my life
    Drax-Quin's Avatar
    February 2007
    2,121 Posts
    Am I right in understanding that it's generally a good practise to keep graphics renderers separate from the application so you can switch between an openGL/DX renderer for example?
    Separating the coupling of implementation from interface is always a good thing. You should look into things like Abstract Factories and Builder patterns to really get the most out of making sure that you can easily interchange things in a program. Or you could just write a Graphics Wrapper that Abstracts OpenGL and DirectX.
    Reply With Quote Edit / Delete Windows 7 United Kingdom Show Events

  13. Post #2653
    Gold Member
    Jookia's Avatar
    July 2007
    6,768 Posts
    You have no idea how much I want Linux. But I'm using my dad's pc and he gets all pissy about it even when I mention it to him.
    Virtualbox?
    Reply With Quote Edit / Delete Linux Australia Show Events Agree Agree x 1 (list)

  14. Post #2654
    Meatpuppet's Avatar
    July 2010
    6,696 Posts
    Virtualbox?
    He would uninstall it.
    Reply With Quote Edit / Delete Windows 7 United States Show Events Funny Funny x 5Dumb Dumb x 1 (list)

  15. Post #2655
    Richy19's Avatar
    May 2010
    5,368 Posts
    your own computer?
    Reply With Quote Edit / Delete Linux United Kingdom Show Events Zing Zing x 2Funny Funny x 1 (list)

  16. Post #2656
    Gold Member
    Falcqn's Avatar
    July 2010
    2,985 Posts
    Are there any advantages/disadvantages to linking dynamically rather than statically or vice versa?

    Edited:

    Aside from the whole "what if the user deletes the dll"
    Reply With Quote Edit / Delete Windows 7 United Kingdom Show Events

  17. Post #2657
    Gold Member
    Naelstrom's Avatar
    June 2010
    2,648 Posts
    Are there any advantages/disadvantages to linking dynamically rather than statically or vice versa?

    Edited:

    Aside from the whole "what if the user deletes the dll"
    I find linking dynamically much easier than static; while static doesn't cause as much clutter as dynamic.

    It's mainly preference as far as I know, do what you think is best.
    Reply With Quote Edit / Delete Linux United States Show Events

  18. Post #2658
    Gold Member
    confinedUser's Avatar
    October 2008
    3,534 Posts
    i need help understanding how variable array's work something like
    Code:
    int nums[6] = {0, 1, 2, 3, 4, 5}
    and if i used something like
    Code:
    nums[1]
    what element does this actually reference. I'm sorry for sounding like a complete dumbass I just jumped into learning c++

    Edited:

    the book is saying the second element because numbering starts at 0 so would that mean 1 is the second element?

    Edited:

    it's like 1:30 am aswell so i'm sorry if i am making no sense right now
    Reply With Quote Edit / Delete Windows 7 United States Show Events

  19. Post #2659
    helifreak's Avatar
    May 2011
    527 Posts
    i need help understanding how variable array's work something like
    Code:
    int nums[6] = {0, 1, 2, 3, 4, 5}
    and if i used something like
    Code:
    nums[1]
    what element does this actually reference. I'm sorry for sounding like a complete dumbass I just jumped into learning c++

    Edited:

    the book is saying the second element because numbering starts at 0 so would that mean 1 is the second element?

    Edited:

    it's like 1:30 am aswell so i'm sorry if i am making no sense right now
    It would depend on the language but in most arrays are zero based (that I know of) so it would be 1.
    Reply With Quote Edit / Delete Windows 7 Australia Show Events Agree Agree x 1 (list)

  20. Post #2660
    ArgvCompany's Avatar
    June 2012
    549 Posts
    i need help understanding how variable array's work something like
    Code:
    int nums[6] = {0, 1, 2, 3, 4, 5}
    and if i used something like
    Code:
    nums[1]
    what element does this actually reference. I'm sorry for sounding like a complete dumbass I just jumped into learning c++

    Edited:

    the book is saying the second element because numbering starts at 0 so would that mean 1 is the second element?

    Edited:

    it's like 1:30 am aswell so i'm sorry if i am making no sense right now
    It's zero based in C++.
    Reply With Quote Edit / Delete Windows 7 Germany Show Events

  21. Post #2661

    January 2012
    131 Posts
    i need help understanding how variable array's work something like
    Code:
    int nums[6] = {0, 1, 2, 3, 4, 5}
    and if i used something like
    Code:
    nums[1]
    what element does this actually reference. I'm sorry for sounding like a complete dumbass I just jumped into learning c++

    Edited:

    the book is saying the second element because numbering starts at 0 so would that mean 1 is the second element?

    Edited:

    it's like 1:30 am aswell so i'm sorry if i am making no sense right now
    It's easy: imagine yourself array as shelves: you put stuff in them (numbers, strings, chars etc)
    int drawer[4] = {10, 20, 30, 40};
    
    , and when you need something, you just open the shelf at it's index:
    /*
        -----------
       |  shelf 0  |
        -----------
       |  shelf 1  |
        -----------
       |  shelf 2  |
        -----------
       |  shelf 3  |
        -----------
    */
    int a = drawer[1];
    
    and variable "a" becomes    20   
    Reply With Quote Edit / Delete Windows XP Russian Federation Show Events Agree Agree x 1 (list)

  22. Post #2662
    Team Hamster
    Mordi's Avatar
    January 2012
    312 Posts
    How would you go about and round a number to the nearest x? For example, rounding to nearest decimal, rounding to nearest 5, and so on.
    Reply With Quote Edit / Delete Windows 7 Norway Show Events

  23. Post #2663
    Gold Member
    ralle105's Avatar
    October 2005
    4,627 Posts
    How would you go about and round a number to the nearest x? For example, rounding to nearest decimal, rounding to nearest 5, and so on.
    rounded = math.Round(num/nearest)*nearest
    
    Reply With Quote Edit / Delete Windows 7 Sweden Show Events Agree Agree x 1 (list)

  24. Post #2664
    Team Hamster
    Mordi's Avatar
    January 2012
    312 Posts
    rounded = math.Round(num/nearest)*nearest
    
    I guess it would be relevant in this case to note that I am working in C++, where there doesn't seem to be a round-function. However, it should be possible by flooring to an integer and multiplying/dividing from there, but I don't know exactly how.

    Nevermind, this seems to work. Thanks!
    value = (GLint)((value / step) + 0.5f) * step;
    Reply With Quote Edit / Delete Windows 7 Norway Show Events

  25. Post #2665
    Gold Member
    ralle105's Avatar
    October 2005
    4,627 Posts
    Oh sorry I thought I was in the lua waywo
    Reply With Quote Edit / Delete Windows 7 Sweden Show Events

  26. Post #2666
    I love my country, but I'm ashamed of my government.
    wakeboarderCWB's Avatar
    February 2010
    697 Posts
    I've begun relearning Java since I understand programming more, now, and I'm stuck on a certain concept: interfaces.

    I do not really understand the use of them. Can someone give me a brief explanation and maybe an example of where it's used?

    Thanks
    Reply With Quote Edit / Delete Windows 7 United States Show Events

  27. Post #2667
    Gold Member
    esalaka's Avatar
    July 2007
    10,069 Posts
    I've begun relearning Java since I understand programming more, now, and I'm stuck on a certain concept: interfaces.

    I do not really understand the use of them. Can someone give me a brief explanation and maybe an example of where it's used?

    Thanks
    I'd type you the classic Animal inheritance example but I can't remember it right now.

    Basically, interfaces define a set of methods (namely, the interface of the objects) which the classes that implement it then... implement. After that, you can create an instance of any single implementation class and use them as if they were of the interface type. (For example, if you have class A, class B and interface I, and the two classes implement I, you could have a variable x of type I which could then contain instances of both A and B.)
    Reply With Quote Edit / Delete Windows 7 Finland Show Events Informative Informative x 1 (list)

  28. Post #2668
    Gold Member
    Naelstrom's Avatar
    June 2010
    2,648 Posts
    I guess it would be relevant in this case to note that I am working in C++, where there doesn't seem to be a round-function. However, it should be possible by flooring to an integer and multiplying/dividing from there, but I don't know exactly how.

    Nevermind, this seems to work. Thanks!
    value = (GLint)((value / step) + 0.5f) * step;
    Casting to an int seems a little dirty, you should use floor() from cmath like so:
    Code:
    float round(float a)
    {
        return floor(a+0.5);
    }
    Value = round(Value/Nearest)*Nearest;
    Reply With Quote Edit / Delete Linux United States Show Events

  29. Post #2669
    I love my country, but I'm ashamed of my government.
    wakeboarderCWB's Avatar
    February 2010
    697 Posts
    I'd type you the classic Animal inheritance example but I can't remember it right now.

    Basically, interfaces define a set of methods (namely, the interface of the objects) which the classes that implement it then... implement. After that, you can create an instance of any single implementation class and use them as if they were of the interface type. (For example, if you have class A, class B and interface I, and the two classes implement I, you could have a variable x of type I which could then contain instances of both A and B.)
    Oh! I get it much better now.

    Thanks a bunch!
    Reply With Quote Edit / Delete Windows 7 United States Show Events

  30. Post #2670
    Gold Member
    Neo Kabuto's Avatar
    November 2008
    5,641 Posts
    I've begun relearning Java since I understand programming more, now, and I'm stuck on a certain concept: interfaces.

    I do not really understand the use of them. Can someone give me a brief explanation and maybe an example of where it's used?

    Thanks
    An interface is sort of a different type of polymorphism than you're probably used to. Instead of extending another object, you implement an interface to support the functionality, which allows you to essentially have multiple inheritances on a class while still being able to have the class hierarchy you want. Interfaces use abstract methods, so all the real code is defined in the implementing class instead of the interface itself, but the interface defines the ways it connects with other objects. They set standards for classes to interact with each other, so different programmers can have code that works well together by implementing the same interfaces.

    A lot of functions and classes in Java are set up to use interfaces to allow any type of class to be used, while still requiring them to meet a standard for usage. For example, the Comparable interface, which tells Java your class includes code for the compareTo method, and allows you to use the built in classes to sort a Collection of that class.
    Reply With Quote Edit / Delete Windows Vista United States Show Events Informative Informative x 1 (list)

  31. Post #2671
    I love my country, but I'm ashamed of my government.
    wakeboarderCWB's Avatar
    February 2010
    697 Posts
    An interface is sort of a different type of polymorphism than you're probably used to. Instead of extending another object, you implement an interface to support the functionality, which allows you to essentially have multiple inheritances on a class while still being able to have the class hierarchy you want. Interfaces use abstract methods, so all the real code is defined in the implementing class instead of the interface itself, but the interface defines the ways it connects with other objects. They set standards for classes to interact with each other, so different programmers can have code that works well together by implementing the same interfaces.

    A lot of functions and classes in Java are set up to use interfaces to allow any type of class to be used, while still requiring them to meet a standard for usage. For example, the Comparable interface, which tells Java your class includes code for the compareTo method, and allows you to use the built in classes to sort a Collection of that class.
    Wow, great explanation! Thanks.

    So interfaces basically are a guidance to what the class will do? I don't essentially need them, correct?
    Reply With Quote Edit / Delete Windows 7 United States Show Events

  32. Post #2672
    Gold Member
    Neo Kabuto's Avatar
    November 2008
    5,641 Posts
    Wow, great explanation! Thanks.

    So interfaces basically are a guidance to what the class will do? I don't essentially need them, correct?
    You don't need them, but it's a very common object-oriented programming design pattern, so expect to use them at least occasionally. APIs for Java also tend to use them a lot.
    Reply With Quote Edit / Delete Windows Vista United States Show Events Informative Informative x 1 (list)

  33. Post #2673
    I love my country, but I'm ashamed of my government.
    wakeboarderCWB's Avatar
    February 2010
    697 Posts
    You don't need them, but it's a very common object-oriented programming design pattern, so expect to use them at least occasionally. APIs for Java also tend to use them a lot.
    Yeah, thanks a lot! Both you and eslaka were a great help and I appreciate it very much!
    Reply With Quote Edit / Delete Windows 7 United States Show Events Friendly Friendly x 2 (list)

  34. Post #2674
    Team Hamster
    Mordi's Avatar
    January 2012
    312 Posts
    Casting to an int seems a little dirty, you should use floor() from cmath like so:
    Code:
    float round(float a)
    {
        return floor(a+0.5);
    }
    Value = round(Value/Nearest)*Nearest;
    Hmm, I understand what you mean but I don't see how it's dirty. Although I'm no expert in C++ by any means.
    Reply With Quote Edit / Delete Windows 7 Norway Show Events Agree Agree x 1 (list)

  35. Post #2675
    Gold Member
    Neo Kabuto's Avatar
    November 2008
    5,641 Posts
    Hmm, I understand what you mean but I don't see how it's dirty. Although I'm no expert in C++ by any means.
    I'm not sure it applies in this case, but some type casts have undefined behavior, and might not be the same on all systems. Pretty sure ints in C++ aren't like that now, though.
    Reply With Quote Edit / Delete Windows Vista United States Show Events

  36. Post #2676
    Mr Kirill's Avatar
    January 2008
    328 Posts
    I'm having trouble with basic trigonometry:

    Basically, I have a ball that's supposed to bounce off a line.



    Values that I know: the ball's coordinates, coordinates of 2 points on the line, coordinates of intersection point of the ball's traectory and the line, X and Y velocities of the ball.

    I need to calculate the new X and Y velocities after the ball bouncing off the line! No gravity or friction needed.


    I feel like this is something simple but unfortunately my math skills have failed me, and I don't even know what this is called to look it up. Please help if you can!
    Reply With Quote Edit / Delete Windows 7 Latvia Show Events Artistic Artistic x 1 (list)

  37. Post #2677
    open.gl
    Overv's Avatar
    February 2007
    7,431 Posts
    The three important variables here are N (normal of the collision surface), v (incoming velocity) and V (new velocity).

    The normal of the collision surface can be calculated by taking the cross product of the vector from A to B and the up vector:



    This can be simplified by working out the cross product:



    The incoming velocity v is already given, as you indicated in your post. Reflection in physics works like this:



    That means that the angle between N and v must be the same as the angle between N and V. This problem would be easy to solve if the line was exactly horizontal. Then we could simply negate the y velocity and keep the x velocity. So, why not change the problem so it's exactly like that? Let's rotate the problem!

    We first need the angle to rotate the problem around so that the line is horizontal. This can be easily calculated with the inverse tangens. We'll call this angle theta.



    In your example case, it would be around 40 degrees. Now let's rotate the problem by -theta so that the line is flat. This requires you to rotate the velocity as well:



    v' is the incoming velocity after rotating the problem. The rotated outgoing velocity is now very easy to determine because this is an easy problem to solve:





    The x velocity is unaffected, but the ball will now go upwards (or downwards dependent on incidence angle). Now the only thing that remains is rotating the problem back with +theta:



    When substituting the intermediate steps, the solution becomes:



    Unfortunately I don't know enough about math to be able to simplify this, but this will at least get you your post collision velocity.
    Reply With Quote Edit / Delete Windows 7 Netherlands Show Events Winner Winner x 4Informative Informative x 2Useful Useful x 1 (list)

  38. Post #2678
    Mr Kirill's Avatar
    January 2008
    328 Posts
    Thank you SO much, Overv! It all makes sense now!
    Reply With Quote Edit / Delete Windows 7 Latvia Show Events Optimistic Optimistic x 1 (list)

  39. Post #2679
    open.gl
    Overv's Avatar
    February 2007
    7,431 Posts
    It seems I lied about N being of any relevance at all, but I hope I helped you out well :p
    Reply With Quote Edit / Delete Windows 7 Netherlands Show Events

  40. Post #2680
    ECrownofFire's Avatar
    January 2011
    1,971 Posts
    Well, any cos(-θ) can be flipped to plain cos(θ). This is because cosine is an even function and is therefore mirrored across the Y axis. In other words, positive x and negative x both give the same result.

    Also, any -sin(-θ) can be rewritten as plain sin(θ). The sine function is an odd function, and therefore -f(-x) = f(x). Note that θ MUST be negative for this one to work.
    Reply With Quote Edit / Delete Windows XP United States Show Events Agree Agree x 1 (list)