• What Do You Need Help With? V6
    7,544 replies, posted
[QUOTE=NixNax123;46505340]This works (you mean AND instead of OR), except it acts a bit wonky. It only stops the camera from moving if the player is near both the x and y boundaries. [editline]16th November 2014[/editline] [code] public static void handleEdges() { Vector2f playerPos = GameScreen.getCurrentPlayer().getPos(); if (playerPos.x > -GameScreen.getBounds().x + cam.getSize().x / 2 && playerPos.x < GameScreen.getBounds().x - cam.getSize().x / 2) { camPos = GameScreen.getCurrentPlayer().getPos(); } if (playerPos.y > -GameScreen.getBounds().y + cam.getSize().y / 2 && playerPos.y < GameScreen.getBounds().y - cam.getSize().y / 2) { camPos = GameScreen.getCurrentPlayer().getPos(); } cam.setCenter(camPos);[/code] [editline]16th November 2014[/editline] what's happening: [vid]http://a.pomf.se/guwkof.webm[/vid][/QUOTE] Set the x and y independently. Change: [code]camPos = GameScreen.getCurrentPlayer().getPos();[/code] into [code]camPos.x = GameScreen.getCurrentPlayer().getPos().x;[/code] (and y, respectively). That should work, if I'm not thinking wrong.
[QUOTE=NixNax123;46505340]This works (you mean AND instead of OR), except it acts a bit wonky. It only stops the camera from moving if the player is near both the x and y boundaries. [editline]16th November 2014[/editline] [code] public static void handleEdges() { Vector2f playerPos = GameScreen.getCurrentPlayer().getPos(); if (playerPos.x > -GameScreen.getBounds().x + cam.getSize().x / 2 && playerPos.x < GameScreen.getBounds().x - cam.getSize().x / 2) { camPos = GameScreen.getCurrentPlayer().getPos(); } if (playerPos.y > -GameScreen.getBounds().y + cam.getSize().y / 2 && playerPos.y < GameScreen.getBounds().y - cam.getSize().y / 2) { camPos = GameScreen.getCurrentPlayer().getPos(); } cam.setCenter(camPos);[/code] [editline]16th November 2014[/editline] what's happening: [vid]http://a.pomf.se/guwkof.webm[/vid][/QUOTE] That's why I said set the X and Y independently. You've got [code] camPos = GameScreen.getCurrentPlayer().getPos();[/code] in both conditionals. Put [code] camPos.x = GameScreen.getCurrentPlayer().getPos().x; [/code] Which shouldn't be a problem because SFML defines sf::Vector2f for this exact situation. If you're not using them already, you should be using sf::Vector2f for all x and y related issues going forward.
[QUOTE=Tommyx50;46505441]Set the x and y independently. Change: [code]camPos = GameScreen.getCurrentPlayer().getPos();[/code] into [code]camPos.x = GameScreen.getCurrentPlayer().getPos().x;[/code] (and y, respectively). That should work, if I'm not thinking wrong.[/QUOTE] Thank you so much! That worked like a charm!
camPos = new vector2f(WhateverX, camPos.y); ?
Is anyone familiar with GJK collision detection? I'm using the expanding polytope algorithm to try and find the penetration depth of the two polygons, and sometimes it results in negative values for depth. Flipping them to positive seems to result in penetration depths that look reasonable enough compared to what I see on screen, but I don't really know how to verify it and I want to make sure that I haven't screwed anything up.
[QUOTE=HumbleTH;46505213]I've been looking into reading an XML file with Java and I'm not sure how to store the data read. Any suggestions?[/QUOTE] I'm pretty certain there are existing XML libraries for Java. However, if you want to really roll your own implementation, a really straightforward (and assuredly not the most optimized) way to do it would be to follow this general scheme: Have a single "XMLElement" class. Its fields will contain the XML element classname, a String value, a HashMap<String,String> of attributes, and an ArrayList<XMLElement> of children. Then parse your XML recursively, where the form of the XML is interpreted as [code]<classname attr=val> <child_classname attr=val> My string value </child_classname> </classname>[/code] Every time you find an opening "<", you recursively create a new XMLElement and fill in the classname, attributes, and String values. Once you find the closing "/>", the recursive construction returns, and the next line in the parent call is to add it to the current children. Your workflow would look something like this [quote] ~ Create new XMLElement A ~ Set A.classname to "classname" ~ Put "attr"->"val" into A.Attributes ~~ Create new XMLElement B ~~ Set B.classname to "child_classname" ~~ Put "attr"->"val" into B.Attributes ~~ Set B.value to "My string value" ~~ Return ~ Insert B into A's "Children" list ~ Return[/quote] That's how I would do it, anyways, if I wanted to just get it done quick and dirty.
I'm working on a project to recognize numbers using the K Nearest Neighbor algorithm using Python and the OpenCV library. I've looked at some examples online and have it working almost as intended. Some of the numbers are being mis-identified even after giving it more training data, though. Has anybody done anything like this before? What's the best way to do character recognition using Python? Is there anything better to use than KNN?
Who is interested in helping me setup an Arduino for the first time? I got a Pro Mini clone that has one job: -Wait for high logic signal on digital channel 10 (clock signal) -While channel 10 is high, read the logic states on digital channels 2-9 (once per clock tick) -Compare binary states from channels 2-9 with table that translates a binary string to an ASCII character (I've already typed up a conversion table) -Transmit ASCII character through TxD pin at static baud rate (buffered, if possible) -Return to waiting for channel 10 to return high I have never programmed a microcontroller. I'm very much a hardware person.
[QUOTE=NixNax123;46504688]I'm trying to implement a system, like in Terrara, where, when you're at the edges of a map, the camera stops centering around the player. I've already got the camera to center around the player, but how would I accomplish the edge cases?[/QUOTE] Yet another way: [code] void centerScreenOnPlayer(int playerX) { playerX = max(0 + screenWidth/2, min(playerX, mapWidth - screenWidth/2)); /* ... camera setting code ... */ } [/code]
I am doing a C++ assignment and had 3/4ths of it done, and when when i made the final function it broke bloody everything. I had my substring, removestring an insertstring functions 100% finished and working and when I made up my findstring it all broke. if i comment out findstring it still breaks. if I comment out all functions, all four, it STILL breaks. No errors, i just get this; [IMG]http://i.imgur.com/lG6Ky5o.png[/IMG] I have no idea why it broke things its not related to, even when commented out. [URL="http://pastebin.com/Jm7TQJk7"]pastebin of all my code [/URL] since i dont know where he error is coming from
I'm getting "undefined reference to sf::Texture" in C++. I'm sure it has something to do with scope or #include but Im not sure exactly what. I have #include "SFML/Graphics.hpp" in my Mapper.h file, #include "SFML/Graphics.hpp" in my Mapper.cpp file. When I try to define a function like "Mapper::mapFile()", and use sf::Texture in the function, I get the error. what do edit: using codeblocks. sf::texture has worked in another test program before so I don't believe it's a linker error [editline]17th November 2014[/editline] Yup, tried it in another project. all it has thus far is: Game.h [code] #ifndef GAME_H #define GAME_H #include "SFML/Graphics.hpp" class Game { public: Game(); virtual ~Game(); protected: private: sf::Window window; }; #endif // GAME_H [/code] Game.cpp [code] #include "Game.h" #include "SFML/Graphics.hpp" sf::Window window; Game::Game() { } Game::~Game() { //dtor } [/code] error log: [code] -------------- Build: Debug in SFMLDickingAround (compiler: GNU GCC Compiler)--------------- g++ -Wall -g -Iinclude -c /home/collin/Documents/C++/SFML/Pasing/SFMLDickingAround/src/Game.cpp -o obj/Debug/src/Game.o g++ -o bin/Debug/SFMLDickingAround obj/Debug/main.o obj/Debug/src/Game.o obj/Debug/src/Game.o: In function `Game::Game()': /home/collin/Documents/C++/SFML/Pasing/SFMLDickingAround/src/Game.cpp:5: undefined reference to `sf::Window::Window()' obj/Debug/src/Game.o: In function `Game::~Game()': /home/collin/Documents/C++/SFML/Pasing/SFMLDickingAround/src/Game.cpp:10: undefined reference to `sf::Window::~Window()' collect2: error: ld returned 1 exit status Process terminated with status 1 (0 minute(s), 1 second(s)) 2 error(s), 0 warning(s) (0 minute(s), 1 second(s)) [/code] This is in Code::Blocks edit: just read the error log in detail. Added -lsfml-graphics -lsfml-window -lsfml-system to build options and now it works
[QUOTE=Dermock;46511930]I am doing a C++ assignment and had 3/4ths of it done, and when when i made the final function it broke bloody everything. I had my substring, removestring an insertstring functions 100% finished and working and when I made up my findstring it all broke. if i comment out findstring it still breaks. if I comment out all functions, all four, it STILL breaks. No errors, i just get this; [IMG]http://i.imgur.com/lG6Ky5o.png[/IMG] I have no idea why it broke things its not related to, even when commented out. [URL="http://pastebin.com/Jm7TQJk7"]pastebin of all my code [/URL] since i dont know where he error is coming from[/QUOTE] So the exception means you're somewhere reading the memory "0x000000F" which is obviously not supposed to happen because addresses that low are normally allocated by the bios itself. So when i run this in visual studio, press "break" on the dialog it instantly jumps to line 22 for me. [quote] printf("value of index after calling findtring fucntion: %s\n", index);[/quote] If you open the "locals" tab visualstudio "Debug -> Windows -> Locals" you can see the value "index is equal to 15, aka 0xF. The reason why this happens is, when you look at the printf string, you try to print a string("%s"), so it expects the first argument to the function to a be pointer to a string, but instead its the value "15". So the right change would be changing "%s" to "%d". [editline]17th November 2014[/editline] Also don't try to print uninitialized strings [cpp] char result[50]; printf("value of result before calling substring fucntion: %s\n", result); [/cpp] Don't do that, printf only stops reading the string when it runs into the value 0 (aka '\0') that buffer only contains random memory at that point and is not guaranteed to have an 0 any where, you could potentially cause an Access Violation.
[QUOTE=Dermock;46511930]I am doing a C++ assignment and had 3/4ths of it done, and when when i made the final function it broke bloody everything. I had my substring, removestring an insertstring functions 100% finished and working and when I made up my findstring it all broke. if i comment out findstring it still breaks. if I comment out all functions, all four, it STILL breaks. No errors, i just get this; [IMG]http://i.imgur.com/lG6Ky5o.png[/IMG] I have no idea why it broke things its not related to, even when commented out. [URL="http://pastebin.com/Jm7TQJk7"]pastebin of all my code [/URL] since i dont know where he error is coming from[/QUOTE] Since you're saying it still breaks even after commenting out and my friend ran into nearly identical problems last night, make sure you're actually terminating the program. When you get an exception like this and you press F5 it'll just continue without actually modifying the code
It should always compile the program before debugging unless its disabled in the solution configuration manager. You can't debug the application without closing the current debugging session, If you for w/e reason detach or crash the debugger, it will still compile when you press F5 and the linker should run into a "cant write <path>" like error.
[QUOTE=Cold;46513265]So the exception means you're somewhere reading the memory "0x000000F" which is obviously not supposed to happen because addresses that low are normally allocated by the bios itself. So when i run this in visual studio, press "break" on the dialog it instantly jumps to line 22 for me. If you open the "locals" tab visualstudio "Debug -> Windows -> Locals" you can see the value "index is equal to 15, aka 0xF. The reason why this happens is, when you look at the printf string, you try to print a string("%s"), so it expects the first argument to the function to a be pointer to a string, but instead its the value "15". So the right change would be changing "%s" to "%d". [editline]17th November 2014[/editline] Also don't try to print uninitialized strings [cpp] char result[50]; printf("value of result before calling substring fucntion: %s\n", result); [/cpp] Don't do that, printf only stops reading the string when it runs into the value 0 (aka '\0') that buffer only contains random memory at that point and is not guaranteed to have an 0 any where, you could potentially cause an Access Violation.[/QUOTE] I'll keep this in mind when i tackle this tomorrow (dont have VS on my home PC :/) - thanks! With those changes did it build/run?
snip
[QUOTE=Cold;46513662]It should always compile the program before debugging unless its disabled in the solution configuration manager. You can't debug the application without closing the current debugging session, If you for w/e reason detach or crash the debugger, it will still compile when you press F5 and the linker should run into a "cant write <path>" like error.[/QUOTE] I don't know, but that's what happened to him. He'd press the break button on that dialog because he didn't want to continue or ignore, modify code around and press F5 which would just continue at the exception
[QUOTE=Dermock;46514851]I'll keep this in mind when i tackle this tomorrow (dont have VS on my home PC :/) - thanks! With those changes did it build/run?[/QUOTE] update; with your proposed changes and a few others I got it running 100% with no errors. thanks!
Alright, so I'm trying to handle object collisions while account for size / momentum... [code] public static void handleElasticCollisions(Entity a, Entity b) { // make a few variables to make equations easier to read Vector2f aPos = a.getPos(); Vector2f bPos = b.getPos(); Vector2f aV = a.getVelocity(); Vector2f bV = b.getVelocity(); float aMass = a.getSize(); float bMass = b.getSize(); // find unit normal vector Vector2f uN = normalize(Vector2f.sub(bPos, aPos)); // find unit tanget vector Vector2f uT = new Vector2f(-uN.y, uN.x); // get normal and tangential components of both velocity vectors // before the collision float aVn = dot(uN, aV); float aVt = dot(uT, aV); float bVn = dot(uN, bV); float bVt = dot(uT, bV); // get normal and tangential components of both velocity vectors // after the collision float aVN = (aVn*(aMass - bMass) + 2*bMass*bVn)/(aMass + bMass); float aVT = aVt; float bVN = (bVn*(bMass - aMass) + 2*aMass*aVn)/(aMass + bMass); float bVT = bVt; // convert normal and tangential components into vectors Vector2f avn = Vector2f.mul(uN, aVN); Vector2f avt = Vector2f.mul(uT, aVT); Vector2f bvn = Vector2f.mul(uN, bVN); Vector2f bvt = Vector2f.mul(uT, bVT); a.setVelocity(Vector2f.add(avn, avt)); b.setVelocity(Vector2f.add(bvn, bvt)); }[/code] So this works most of the time. However, sometimes, objects go inside one another / are stuck to each other, and this causes them to "orbit" one another (while staying inside). Obviously, this is wrong. What's happening? [editline]18th November 2014[/editline] This is how I check for collision: [code] public boolean intersectsWithAsteroid() { for (Entity e : GameScreen.getEntities()) { if (e instanceof AsteroidEntity && asteroidSprite.getGlobalBounds().intersection(e.getBounds()) != null && !this.equals(e)) { collidingAsteroid = (AsteroidEntity)e; return true; } } return false; }[/code] [editline]18th November 2014[/editline] Intersection() returns a rectangle of intersection between two sprites, and if the return value is null, then there is no intersection.
How do you do gravity? I understand the principle of m/s^2, but would sometime like: [code] for(int i = 0; i < (1/2)*period; i ++){ player.setY(sin(i)); } [/code] work? I forgot how to calculate the period of something, but theoretically it would give you a nice round jump.
Trying to work on a text rpg for my first project in c++, thought this would be a good way to go beyond the guess the number type games. What I have is functional but I can't figure out how to move the space for the user input. [img]http://i.imgur.com/TbVGLVF.png[/img] So as seen in the picture, I'm trying to move the input space into that box, any thoughts/ideas? Right now it just displays the last thing the user entered.
How would I make an updating system, so say every x minutes, an image would change on the website for everyone? I'm making a thing where the site gives everyone the same new puzzle every x amt of minutes, and want to where I would start.
[QUOTE=NixNax123;46518131]Alright, so I'm trying to handle object collisions while account for size / momentum... [code] public static void handleElasticCollisions(Entity a, Entity b) { // make a few variables to make equations easier to read Vector2f aPos = a.getPos(); Vector2f bPos = b.getPos(); Vector2f aV = a.getVelocity(); Vector2f bV = b.getVelocity(); float aMass = a.getSize(); float bMass = b.getSize(); // find unit normal vector Vector2f uN = normalize(Vector2f.sub(bPos, aPos)); // find unit tanget vector Vector2f uT = new Vector2f(-uN.y, uN.x); // get normal and tangential components of both velocity vectors // before the collision float aVn = dot(uN, aV); float aVt = dot(uT, aV); float bVn = dot(uN, bV); float bVt = dot(uT, bV); // get normal and tangential components of both velocity vectors // after the collision float aVN = (aVn*(aMass - bMass) + 2*bMass*bVn)/(aMass + bMass); float aVT = aVt; float bVN = (bVn*(bMass - aMass) + 2*aMass*aVn)/(aMass + bMass); float bVT = bVt; // convert normal and tangential components into vectors Vector2f avn = Vector2f.mul(uN, aVN); Vector2f avt = Vector2f.mul(uT, aVT); Vector2f bvn = Vector2f.mul(uN, bVN); Vector2f bvt = Vector2f.mul(uT, bVT); a.setVelocity(Vector2f.add(avn, avt)); b.setVelocity(Vector2f.add(bvn, bvt)); }[/code] So this works most of the time. However, sometimes, objects go inside one another / are stuck to each other, and this causes them to "orbit" one another (while staying inside). Obviously, this is wrong. What's happening? [editline]18th November 2014[/editline] This is how I check for collision: [code] public boolean intersectsWithAsteroid() { for (Entity e : GameScreen.getEntities()) { if (e instanceof AsteroidEntity && asteroidSprite.getGlobalBounds().intersection(e.getBounds()) != null && !this.equals(e)) { collidingAsteroid = (AsteroidEntity)e; return true; } } return false; }[/code] [editline]18th November 2014[/editline] Intersection() returns a rectangle of intersection between two sprites, and if the return value is null, then there is no intersection.[/QUOTE] I'm not too sure (never implemented collision *response*, only detection), but it may be that your are checking the collision detection not enough, meaning objects can get stuck inside each other more likely. Have you tried increasing the amount of times you are calculating physics every frame?
I fixed it! It turns out, things had a chance of colliding with each other multiple times in the same frame, and the physics calculation would execute for all of those, getting weird results. I just compared the colliding object to the previous object collided with and that fixed it! [editline]18th November 2014[/editline] [QUOTE=Tommyx50;46520947]I'm not too sure (never implemented collision *response*, only detection), but it may be that your are checking the collision detection not enough, meaning objects can get stuck inside each other more likely. Have you tried increasing the amount of times you are calculating physics every frame?[/QUOTE] I actually didn't fix it, can you show me a good way of handling collision between two rectangles? My error might be in that implementation. [editline]18th November 2014[/editline] Also, if I'm updated my loop on a fluid time step, while looping through ànd updating entities each iteration of the loop, would that be too slow and cause problems?
[QUOTE=Meepbob;46520288]Trying to work on a text rpg for my first project in c++, thought this would be a good way to go beyond the guess the number type games. What I have is functional but I can't figure out how to move the space for the user input. [img]http://i.imgur.com/TbVGLVF.png[/img] So as seen in the picture, I'm trying to move the input space into that box, any thoughts/ideas? Right now it just displays the last thing the user entered.[/QUOTE] You want to look into something like [url=http://en.wikipedia.org/wiki/Curses_(programming_library)]curses[/url]. For Linux C/C++ programs, you can use [url=http://en.wikipedia.org/wiki/Ncurses]ncurses[/url]. For Windows, there is [url=http://en.wikipedia.org/wiki/PDCurses]pdcurses[/url].
[QUOTE=Gmod4ever;46522051]You want to look into something like [url=http://en.wikipedia.org/wiki/Curses_(programming_library)]curses[/url]. For Linux C/C++ programs, you can use [url=http://en.wikipedia.org/wiki/Ncurses]ncurses[/url]. For Windows, there is [url=http://en.wikipedia.org/wiki/PDCurses]pdcurses[/url].[/QUOTE] Wow, this is really neat. Thanks a lot! Exactly what I was looking for.
If my game loop is: [code] public void show() { // etc... // set delta time float currentTime = clock.getElapsedTime().asSeconds(); float dt = currentTime - lastTime; Window.getWindow().draw(backgroundSprite); // reset removal list entsToBeRemoved.clear(); // update entities and check for removal for (Entity e : entities) { e.update(dt); if (e.toBeRemoved()) { entsToBeRemoved.add(e); } } // draw entities for (Entity e : entities) { e.draw(); } // draw player last so bullets appear to come out of player (not from center) player.draw(); player.update(dt); // etc... Window.getWindow().display(); lastTime = currentTime; }[/code] And I perform collision checking in the update() function of my entities, how would I make it so that the update function is performed using a fixed time step? [editline]18th November 2014[/editline] Specifically, I need the last example here: [url]http://gafferongames.com/game-physics/fix-your-timestep/[/url] But applied to my game loop. If someone could help me do this, that would be fucking amazing and I would love you forever.
[QUOTE=NixNax123;46522404]If my game loop is: [code] public void show() { // etc... // set delta time float currentTime = clock.getElapsedTime().asSeconds(); float dt = currentTime - lastTime; Window.getWindow().draw(backgroundSprite); // reset removal list entsToBeRemoved.clear(); // update entities and check for removal for (Entity e : entities) { e.update(dt); if (e.toBeRemoved()) { entsToBeRemoved.add(e); } } // draw entities for (Entity e : entities) { e.draw(); } // draw player last so bullets appear to come out of player (not from center) player.draw(); player.update(dt); // etc... Window.getWindow().display(); lastTime = currentTime; }[/code] And I perform collision checking in the update() function of my entities, how would I make it so that the update function is performed using a fixed time step? [editline]18th November 2014[/editline] Specifically, I need the last example here: [url]http://gafferongames.com/game-physics/fix-your-timestep/[/url] But applied to my game loop. If someone could help me do this, that would be fucking amazing and I would love you forever.[/QUOTE] Instead of passing in (dt), pass in a constant value, like 0.02 or something. that makes it fixed. If you want the semi-fixed solution shown, it makes thing a lot more complicated because you need to interpolate to stop juddering. Anyways, I don't think that'd fix your issue. Maybe just try doing something like this: [code] for(int i = 1; i < physIterations; i++( { for (Entity e : entities) { e.update(dt / physIterations); if (e.toBeRemoved()) { entsToBeRemoved.add(e); } } } [/code] That would increase your physics iterations without much complexity.
[QUOTE=Tommyx50;46523553]Instead of passing in (dt), pass in a constant value, like 0.02 or something. that makes it fixed. If you want the semi-fixed solution shown, it makes thing a lot more complicated because you need to interpolate to stop juddering. Anyways, I don't think that'd fix your issue. Maybe just try doing something like this: [code] for(int i = 1; i < physIterations; i++( { for (Entity e : entities) { e.update(dt / physIterations); if (e.toBeRemoved()) { entsToBeRemoved.add(e); } } } [/code] That would increase your physics iterations without much complexity.[/QUOTE] What do you suggest a good starting value for physIterations be? A general ballpark value, just so I know what to test. [editline]18th November 2014[/editline] I'm trying 5, and that still don't fix my issue. What could be causing this? I'm SO CLOSE. [editline]18th November 2014[/editline] I updated my repo with the physics stuff, so you can see the context: [url]https://github.com/Tetramputechture/Corraticca[/url] [editline]18th November 2014[/editline] And here's the .zip, so you can see exactly what my problem is: [url]http://www.filedropper.com/corattica[/url]
Snip wrong thread.
Sorry, you need to Log In to post a reply to this thread.