• What do you need help with? Version 1
    5,001 replies, posted
[QUOTE=MakeR;26605955][cpp]vx /= pow(Friction, DeltaT);[/cpp][/QUOTE] I think I'm missing something here but that doesn't look like friction. That would apply acceleration proportional to the velocity, which isn't friction. Assuming Friction is given in units per second squared, shouldn't it be something like [cpp]if (vx<0){ if (Friction*DeltaT>-vx) vx=0; else vx+=Friction*DeltaT; }else if(vx>0){ if (vx-Friction*DeltaT<0) vx=0; else vx-=Friction*DeltaT; }[/cpp] It's a bit more complicated and could probably be cleaned up a bit, but that looks more like friction. It's still not perfect, but we don't really need the accuracy of something like this: [cpp]int vSign=((vs>0)*2-1); vx=vSign*min(sqrt(vx*vx-2*Friction*vx*vSign*DeltaT),0);[/cpp]
[QUOTE=Metroid48;26607068]I think I'm missing something here but that doesn't look like friction. That would apply acceleration proportional to the velocity, which isn't friction. Assuming Friction is given in units per second squared, shouldn't it be something like [cpp]if (vx<0){ if (Friction*DeltaT>-vx) vx=0; else vx+=Friction*DeltaT; }else if(vx>0){ if (vx-Friction*DeltaT<0) vx=0; else vx-=Friction*DeltaT; }[/cpp] It's a bit more complicated and could probably be cleaned up a bit, but that looks more like friction. It's still not perfect, but we don't really need the accuracy of something like this: [cpp]int vSign=((vs>0)*2-1); vx=vSign*min(sqrt(vx*vx-2*Friction*vx*vSign*DeltaT),0);[/cpp][/QUOTE] I wasn't actually giving him an equation to simulate friction, just how to take frametime into consideration when multiplying or dividing. Maybe I should have used different variable names to avoid confusion.
[QUOTE=MakeR;26607173]I wasn't actually giving him an equation to simulate friction, just how to take frametime into consideration when multiplying or dividing. Maybe I should have used different variable names to avoid confusion.[/QUOTE] Oh, so it was because he already had vx/=Friction. Thanks for clearing that up! [b]Edit:[/b] Though, to simulate division based on time it has to be ordered slightly differently. If you wanted to, say, divide by 2 for every second, it'd be like this: [cpp]vx*=pow(1/2,DeltaT);[/cpp] [b]Edit2:[/b][QUOTE=MakeR;26608282]No it doesn't, the way I posted earlier works just fine. i.e. [cpp]vx/=pow(2, DeltaT)[/cpp][/QUOTE] Yeah, looking again you're right.
[QUOTE=Metroid48;26607205]Though, to simulate division based on time it has to be ordered slightly differently. If you wanted to, say, divide by 2 for every second, it'd be like this: [cpp]vx*=pow(1/2,DeltaT);[/cpp][/QUOTE] No it doesn't, the way I posted earlier works just fine. i.e. [cpp]vx/=pow(2, DeltaT)[/cpp]
Really stupid question... but what is the correct way of creating a rect in SFML? First I did: [cpp]rect = sf::Shape::Rectangle(x, y, x+w, y+h, col);[/cpp] With x and y the upper-left corner of the rectangle. But then, stuff like SetRotation and GetPointPosition(n) wouldn't work normally. So now, after trying out some of the methods in the documentation, I achieved the correct behaviour with this: [cpp]rect = sf::Shape::Rectangle(0, 0, w, h, col); rect.SetCenter(w/2, h/2); rect.Move(cenx, ceny);[/cpp] Is this correct? It feels... strange that the x and y in the constructor have to be 0, and I later have to move the thing. I also find it strange it doesn't automatically set its center.
sf::Shape::Rectangle rect = sf::Shape::Rectangle(x, y, x+w, y+h, col);
sf::Shape::Rectangle isn't a type, it's sf::Shape (sf::Shape::Rectangle is helper function or something). I do have rect defined as a sf::Shape, if you mean that ;)
[QUOTE=Metroid48;26603327]First, TGAheader looks like it's missing the colour depth. Try {0,0,2,0,0,0,0,32,0,0,0,0} But I doubt that's causing the issue, so it's something to do with OpenGL. Use glGetError to check if there are any issues immediately after [url=http://www.opengl.org/sdk/docs/man/xhtml/glReadPixels.xml]glReadPixels[/url]. [editline]10th December 2010[/editline] If bmp's easiest then tga is tied with it! I've never used bmp but with tga you just write a simple header and then the raw data.[/QUOTE] Added the new header and nothing happened. glGetError() also returned nothing.
For that guy who's having trouble with TGA, I just made this for myself. Might help a bit. [img]http://gyazo.com/05963b6882abac4c7d4e6aa100b85517.png[/img]
[QUOTE=Overv;26613926]For that guy who's having trouble with TGA, I just made this for myself. Might help a bit. [img_thumb]http://gyazo.com/05963b6882abac4c7d4e6aa100b85517.png[/img_thumb][/QUOTE] media/imgthumb tag that shit
[QUOTE=Overv;26613926]...[/QUOTE] That actually answers a few other things I was wondering as well, thanks. I'm working on a conway's game of life now (I pretty much scrapped the n-body sim for a later time) and I'm wondering what I've done that's made it so that the Y cells count the neighbours of the opposite side. [code] int neighbourCount(int cellX, int cellY) { int n=0; if(grid[cellX-1][cellY+1]==1) n++; //grid is table with all the cells. 1 is a live cell, 0 is a dead cell. if(grid[cellX][cellY+1]==1) n++; if(grid[cellX+1][cellY+1]==1) n++; if(grid[cellX+1][cellY]==1) n++; if(grid[cellX+1][cellY-1]==1) n++; if(grid[cellX][cellY-1]==1) n++; if(grid[cellX-1][cellY-1]==1) n++; if(grid[cellX-1][cellY]==1) n++; return n; } void rules() { int i, j; for(i=0;i<bSize;i++) //bSize is the length/width of the cell grid. { for(j=0;j<bSize;j++) { switch(neighbourCount(i,j)) { case 2: break; case 3: grid[i][j]=1; break; default: grid[i][j]=0; } } } } [/code]
[QUOTE=Chozo;26609413]Really stupid question... but what is the correct way of creating a rect in SFML? First I did: [cpp]rect = sf::Shape::Rectangle(x, y, x+w, y+h, col);[/cpp] With x and y the upper-left corner of the rectangle. But then, stuff like SetRotation and GetPointPosition(n) wouldn't work normally. So now, after trying out some of the methods in the documentation, I achieved the correct behaviour with this: [cpp]rect = sf::Shape::Rectangle(0, 0, w, h, col); rect.SetCenter(w/2, h/2); rect.Move(cenx, ceny);[/cpp] Is this correct? It feels... strange that the x and y in the constructor have to be 0, and I later have to move the thing. I also find it strange it doesn't automatically set its center.[/QUOTE] Which version of SFML are you using?
I'm using SFML 1.6. I understood from the site it was the latest stable release.
[QUOTE=Chozo;26620872]I'm using SFML 1.6. I understood from the site it was the latest stable release.[/QUOTE] 2.0 is pretty much stable, i think they just need to add some stuff to the networks package before they release it
SFML2, although unfinished, is actually very stable and has a lot of cool features new in it; I recommend it. I'm not sure if it will fix your problem, but it may because I remember I had problems with moving sf::Shape objects with older versions as well.
[QUOTE=Overv;26613926]For that guy who's having trouble with TGA, I just made this for myself. Might help a bit. [img_thumb]http://gyazo.com/05963b6882abac4c7d4e6aa100b85517.png[/img_thumb][/QUOTE] Looks good, but you have an extraneous FF in your BGR color table.
[QUOTE=Wyzard;26622596]Looks good, but you have an extraneous FF in your BGR color table.[/QUOTE] Yeah, someone pointed that out earlier. I shouldn't be creating explanatory images like that at 5 in the morning.
Trying to implement bullet firing into my project for uni but I'm running into a bit of a problem when firing, as they all seem to fire at once but at different speeds.. [media]http://www.youtube.com/watch?v=rue2HJxNv-c[/media] I think its because when I press the key down to fire them, they are all being fired off at once but I've tried to implement a timer and that still didn't work. Here is the update and firing code for them. [code] void UpdateCannonBalls() { float index = 0; for (int i = 0; i < 10; i++) { if (Bullets[i]->GetAlive()) { index -= 0.3f; Bullets[i]->SetPosition(Bullets[i]->GetPosition().x + index, Bullets[i]->GetPosition().y, Bullets[i]->GetPosition().z); } } } void FireCannonBall() { for (int i = 0; i < 10; i++) { if(!Bullets[i]->GetAlive()) { Bullets[i]->SetAlive(true); Bullets[i]->SetPosition(Car->GetPosition().x,Car->GetPosition().y,Car->GetPosition().z); } } } [/code] Edit: fixed the speed issue, still don't know how to fix them all coming out at once.
It should be like [cpp]void FireCannonBall() { if (BallsToFire == 0 && BallRefireTime >= CurrentTime) BallsToFire = 10; //else: cannot fire yet! } void UpdateCannonBalls() { //update balls if (BallsToFire > 0 && BallRefireTime >= CurrentTime) { //fire cannon ball --BallsToFire; BallRefireTime = CurrentTime + BallRefireDelay; } }[/cpp]
[QUOTE=ZeekyHBomb;26625275]It should be like [cpp]void FireCannonBall() { if (BallsToFire == 0 && BallRefireTime >= CurrentTime) BallsToFire = 10; //else: cannot fire yet! } void UpdateCannonBalls() { //update balls if (BallsToFire > 0 && BallRefireTime >= CurrentTime) { //fire cannon ball --BallsToFire; BallRefireTime = CurrentTime + BallRefireDelay; } }[/cpp][/QUOTE] I'm don't know how to get current time in C++ Edit: Could not not check if the button pressed has been pressed down and then released?
Oh, I thought you wanted to shoot multiple cannon-balls at one button-press, but each one delayed a bit. Well, the error is that you don't break out the loop in FireCannonBall then.
[QUOTE=ZeekyHBomb;26625516]Oh, I thought you wanted to shoot multiple cannon-balls at one button-press, but each one delayed a bit. Well, the error is that you don't break out the loop in FireCannonBall then.[/QUOTE] I realised I didn't include a break just before I read your post, thanks very much for your help anyway :)
What exactly is the difference between "." and "->", I found out it was something about direct and indirect references, but right now it looks like people are just using -> to be hipsters or something.
In C and C++ you use the dot-operator to access members, and the arrow-operator to access members of an object a pointer is pointing to. [cpp]struct SomeStruct { int member; }; //... SomeStruct a, *b = new SomeStruct(); a.member; //okay //a->member; //compiler error //b.member; //compiler error b->member; //okay[/cpp]
Got a problem with my SFML game project. [cpp] void create_line(double x, double y, bool state, int type) { sline tempLine; tempLine.x = x; tempLine.y = y; tempLine.state = state; tempLine.type = type; lines.push_back(tempLine); } void update_line(sf::RenderWindow &target) { for(std::list<sline>::iterator iter = lines.begin(); iter != lines.end(); ++iter) //iterates over each element { if(iter->type == 0) { if((mousey > iter->y) && (mousey > iter->y + 40) && (mousex > iter->x) && (mousex < iter->x + 6)) { //target.Draw(sf::Shape::Rectangle(iter->x, iter->y, iter->x+6, iter->y+40, sf::Color(0, 0, 0, 255), 0, sf::Color(123, 123, 123, 255))); } else { target.Draw(sf::Shape::Rectangle(iter->x, iter->y, iter->x+6, iter->y+40, sf::Color(157, 157, 157, 255), 0, sf::Color(123, 123, 123, 255))); } } else { if(iter->type == 1) { if((mousey > iter->y) && (mousey > iter->y + 6) && (mousex > iter->x) && (mousex < iter->x + 40)) { target.Draw(sf::Shape::Rectangle(iter->x, iter->y, iter->x+40, iter->y+6, sf::Color(0, 0, 0, 255), 0, sf::Color(123, 123, 123, 255))); } else { target.Draw(sf::Shape::Rectangle(iter->x, iter->y, iter->x+40, iter->y+6, sf::Color(157, 157, 157, 255), 0, sf::Color(123, 123, 123, 255))); } } } } } [/cpp] I draw about 40 "lines using" those and my framerate drops incredibly low. Any idea why this code is so inefficient? Btw, the type property of each line determines whether or not it's horizontal or vertical.
It's probably due to re-creating the rectangles each frame. Doing that will not only create and destroy them in the computers RAM, but also on the graphics-cards' RAM (supposing you are using hardware acceleration) and you will wanna try to keep as much traffic away from that pipeline as possible. So have a container of sf::Shapes and check the position of the points to check if it is a horizontal one, or have a container of std::pair<sf::Shape, bool> where the bool is for that purpose.
[QUOTE=ZeekyHBomb;26630496]It's probably due to re-creating the rectangles each frame. Doing that will not only create and destroy them in the computers RAM, but also on the graphics-cards' RAM (supposing you are using hardware acceleration) and you will wanna try to keep as much traffic away from that pipeline as possible. So have a container of sf::Shapes and check the position of the points to check if it is a horizontal one, or have a container of std::pair<sf::Shape, bool> where the bool is for that purpose.[/QUOTE] Aha, thanks man. I understand now!
[QUOTE=Chris220;26621844]SFML2, although unfinished, is actually very stable and has a lot of cool features new in it; I recommend it. I'm not sure if it will fix your problem, but it may because I remember I had problems with moving sf::Shape objects with older versions as well.[/QUOTE]Thanks for the tip, just moved my project to SFML2. Everything seems to work the same, only 'difference' I noticed is that the Center is now called the Origin. It may just be me, but I do find the SFML2 documentation a bit clearer. Also I think I understand now why I have to use several functions in order to achieve 'normal' rotation (around the center of the rectangle). I guess I was a bit confused by the local/global coordinates stuff.
How would I compile [url=http://luaforge.net/projects/pluto/]this[/url] C library for Lua to a .dll with gcc? I can't figure it out for the life of me, and google has been no help.
-snip-
Sorry, you need to Log In to post a reply to this thread.