Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - devon

Pages: [1]
1
Graphics / GetPosition() and arrays of shapes
« on: November 29, 2008, 01:32:00 am »
I was trying to make a scrolling grid using an array shape::lines and ran into a problem when tring to call GetPosition() on each line in the array. It seems to only get the position of the whole array or the first shape in the array as the grid only loops when the first line gets to the bottom and not when each line gets to the bottom. I can just track my own y coords and make it work but am wondering why GetPosition doesn't seem to work with arrays or if I'm doing something wrong in my code (besides passing ints instead of floats...):

Setup:
Code: [Select]
   //Create background lines
int backX[7] = {0,100,200,300,400,500,600};
    int backY[8] = {0,100,200,300,400,500,600,700};
sf::Shape backLinesV[7];
sf::Shape backLinesH[8];
    for (int i = 0; i < 7; i++)
        backLinesV[i] = sf::Shape::Line(backX[i],0,backX[i],winY,2,sf::Color(128,128,128));
    for (int i = 0; i < 8; i++)
        backLinesH[i] = sf::Shape::Line(0,backY[i],winX,backY[i],2,sf::Color(128,128,128));


In main loop:
Code: [Select]
   //Background lines
    for (int i = 0; i < 7; i++)
win.Draw(backLinesV[i]);
    for (int i = 0; i < 8; i++)
    {
win.Draw(backLinesH[i]);
sf::Vector2f Position = backLinesH[i].GetPosition();
        if (Position.y >= 0 && Position.y <= winY)
            backLinesH[i].Move(0,1);
        else
            backLinesH[i].SetPosition(0,0);
    }

2
General / frame rate drops without cout
« on: November 27, 2008, 01:14:07 am »
REALLY WEIRD

Okay I narrowed the problem down to only existing when my laptop is on max cpu speed setting in notebook hardware control. When it's on battery, there is no drop in framerates. Which is ironic because then it runs at 1ghz instead of 1.86ghz.

But this bug is so strange to me! When it's on full cpu power, console output is needed to make the game run at full speed. I'll try uninstalling nhc and see if that is the problem or if it has to do with the hardware cpu stepping. But since it runs fine in ubuntu, I bet it has to do with nhc, or an nhc setting in windows.

3
General / frame rate drops without cout
« on: November 26, 2008, 07:17:21 am »
So I finally figured out how to compile with the static libraries, which basically meant I finally figured out how to use VS2005. Although the debug static libraries still give me this error:

Code: [Select]
mt.exe : general error c101008a: Failed to save the updated manifest to the file ".\Debug\Asterist.exe.embed.manifest". The parameter is incorrect.

The release works fine.

Anyways, after using VS2005 for awhile I noticed my frame rate had dropped considerably, so I added in this to check the frame rate:
Code: [Select]

float Framerate = 1.f / win.GetFrameTime();
cout << Framerate << endl;


and lo and behold the framerate was back at 60 (since I limited it to 60). Further testing revealed simply couting anything to the console made it run at 60fps.

I don't get it? Changing the program to a windows application and leaving cout in there also makes it run slow. Is there a Visual Studio setting that's hanging up the program without console input?

Any help would be appreciated.

4
Graphics / just draw a image, not a sprite
« on: November 21, 2008, 07:33:16 am »
Well maybe creating thousands of sprites a second doesn't impact performance but creating 720 shape::lines a second (at 60fps) on a 1ghz machine has a large impact on performance :). Which is what I found out when I put this in my main loop:

Code: [Select]
void Asteroid::draw(sf::RenderWindow &win)
{
    sf::Shape astShape[12];
    int drawN = 12;
    //Draw asteroid's inner rectangle
    astShape[0] = sf::Shape::Line(x[0],y[0],x[1],y[1],1,sf::Color(255, 255, 255));
    astShape[1] = sf::Shape::Line(x[1],y[1],x[2],y[2],1,sf::Color(255, 255, 255));
    astShape[2] = sf::Shape::Line(x[2],y[2],x[3],y[3],1,sf::Color(255, 255, 255));
    astShape[3] = sf::Shape::Line(x[3],y[3],x[0],y[0],1,sf::Color(255, 255, 255));
   
    //Connect inner rectangle to top vertex
    astShape[4] = sf::Shape::Line(x[0],y[0],x[4],y[4],1,sf::Color(255, 255, 255));
    astShape[5] = sf::Shape::Line(x[1],y[1],x[4],y[4],1,sf::Color(255, 255, 255));
    astShape[6] = sf::Shape::Line(x[2],y[2],x[4],y[4],1,sf::Color(255, 255, 255));
    astShape[7] = sf::Shape::Line(x[3],y[3],x[4],y[4],1,sf::Color(255, 255, 255));

    //Connect inner rectangle to bottom vertex
    astShape[8] = sf::Shape::Line(x[0],y[0],x[5],y[5],1,sf::Color(255, 255, 255));
    astShape[9] = sf::Shape::Line(x[1],y[1],x[5],y[5],1,sf::Color(255, 255, 255));
    astShape[10] = sf::Shape::Line(x[2],y[2],x[5],y[5],1,sf::Color(255, 255, 255));
    astShape[11] = sf::Shape::Line(x[3],y[3],x[5],y[5],1,sf::Color(255, 255, 255));
   
    for(int i =0; i < drawN; i++)
        win.Draw(astShape[i]);
}

5
General / pseudo 3D rotation help
« on: November 21, 2008, 07:25:07 am »
since i'm only moving 4 of the y vertices (so I don't need to worry about matrices), I think keeping track of the y coords as an array, modifying the array with trig functions that rotate the ys on a z circle (which would look like an expanding and contracting line in 2d space)  and then recreating the lines after a few game loop cycles works fine.


But doing it in 3D would be good for me to learn.  It's the basic openGl stuff right? or is there something else you mean by 3D? and I would pass the vertex coordinates to the sfml shape line as new shapes every few game cycles? or use openGl lines and rendering draw them separately? It boils down to basically the same thing, but with more overhead if I use openGL to keep track of all the vertices I think.

6
Graphics / shader support for post fx
« on: November 20, 2008, 04:38:58 pm »
My crappy 945gm express in my laptop says it supports pixel shaders 2.0 but the vertex shaders has this as a subnote next to its 2.0 support:

1 Intel provides an optimized graphics pipeline for shader processing that is included in Microsoft DirectX*. This can be used by games to provide software (SW) shader processing.

So am I correct in assuming I'm SOL for using PostFX and there's no workaround? I really wanted some glow effects :(.

I tried to use them and sure enough SFML would not let me. They really shouldn't call this a directX9 card...

7
General / framerate drops when drawing 100+ shape::lines
« on: November 19, 2008, 08:13:54 am »
yeah throwing this in my main loop did the trick, at least up to 50 asteroids or so.

where theTime = Clock.GetElapsedTime();

Code: [Select]
int intTime = theTime * 100;
//should probably fix this to do a typecast to int
if (intTime %2 == 0)

        {

            asteroid[i].rotate();
//recreate the 12 lines
        }

8
General / framerate drops when drawing 100+ shape::lines
« on: November 19, 2008, 07:04:25 am »
haha yeah, except this is my first game in c++ and openGL is still scary. Although maybe simpler to do what I want than I think.

I only need ~10 asteroids on screen at most.  If I force a them to skip "frames" by making a counter that delays how often a shape is created it might work.

9
General / framerate drops when drawing 100+ shape::lines
« on: November 19, 2008, 06:02:15 am »
That's fine for moving it. But to animate it I don't see any setPoint function, so the only way to change a point in the line is to call Line? And that happens every frame.

10
General / framerate drops when drawing 100+ shape::lines
« on: November 19, 2008, 05:06:03 am »
So in my asteroids game I get some major frame rate drops when I have 10+ asteroids being drawn and when running at 1ghz on battery. When I run the computer at full 1.86ghz the drop is less significant but still noticeable. All the same I want to make my code fast enough to do other things then move lines and be able run on slower computers.

since each asteroid is made up of 12 lines, 10 asteroids is 120 shapes then. And is that what's slowing it down? Is it the overhead for each line to be an individual drawable? Would it be faster to not recreate the shapes each frame and either use pointers to the x and ys?

If I did it in shape::polygons they would be turning concave and convex because of the rotation I have, and I think that may not draw properly.

Here's what happens every frame in the member functions:

Code: [Select]
void Asteroid::draw(sf::RenderWindow &win)
{
    sf::Shape astShape[12];
    int drawN = 12;
    //Draw asteroid's inner rectangle
    astShape[0] = sf::Shape::Line(x[0],y[0],x[1],y[1],1,sf::Color(255, 255, 255));
    astShape[1] = sf::Shape::Line(x[1],y[1],x[2],y[2],1,sf::Color(255, 255, 255));
    astShape[2] = sf::Shape::Line(x[2],y[2],x[3],y[3],1,sf::Color(255, 255, 255));
    astShape[3] = sf::Shape::Line(x[3],y[3],x[0],y[0],1,sf::Color(255, 255, 255));
   
    //Connect inner rectangle to top vertex
    astShape[4] = sf::Shape::Line(x[0],y[0],x[4],y[4],1,sf::Color(255, 255, 255));
    astShape[5] = sf::Shape::Line(x[1],y[1],x[4],y[4],1,sf::Color(255, 255, 255));
    astShape[6] = sf::Shape::Line(x[2],y[2],x[4],y[4],1,sf::Color(255, 255, 255));
    astShape[7] = sf::Shape::Line(x[3],y[3],x[4],y[4],1,sf::Color(255, 255, 255));

    //Connect inner rectangle to bottom vertex
    astShape[8] = sf::Shape::Line(x[0],y[0],x[5],y[5],1,sf::Color(255, 255, 255));
    astShape[9] = sf::Shape::Line(x[1],y[1],x[5],y[5],1,sf::Color(255, 255, 255));
    astShape[10] = sf::Shape::Line(x[2],y[2],x[5],y[5],1,sf::Color(255, 255, 255));
    astShape[11] = sf::Shape::Line(x[3],y[3],x[5],y[5],1,sf::Color(255, 255, 255));
   
    for(int i =0; i < drawN; i++)
        win.Draw(astShape[i]);
}

void Asteroid::move(int winX, int winY)
{  
//Rotate asteroid
y2Angle += spinSpeed;//Increase the angle by the amount of spinSpeed
y4Angle += spinSpeed;
y5Angle += spinSpeed;
y6Angle += spinSpeed;
    y[1] = centerY + radius * sin(y2Angle);//Trig = hypotenuse * sin(destination angle)
    y[3] = centerY + radius * sin(y4Angle);
    y[5] = centerY + radius * sin(y5Angle);
    y[4] = centerY + radius * sin(y6Angle);
   
    //Move asteroid1 down
    for (int i = 0; i < n; i++)
        y[i] += asteroidMoveY;
    centerY += asteroidMoveY;
}

11
General / pseudo 3D rotation help
« on: November 18, 2008, 08:00:56 am »
ah, well that 5 was an old temporary test, but it wasn't the problem.

Basically I was trying to simulate rotating this asteroid shape:



by simply increasing and decreasing the inner and outer diamonds in sync. But I could never get them in sync. If my trig was better I probably would've realized this method that I figured out this evening with a little help from the unit circle and http://www.tutcity.com/view/the-basics-of-3d-rotations.1143.html.

Silly me, thinking algebraic functions would be simpler than trig.  I blame my calc class.

Here's my new code approx that works perfectly and is even simpler:

//init in constructor
double pi = 3.14159;
y2Angle = 0;
y4Angle = pi;
y5Angle = pi/2;
y6Angle = 3 * pi/2;

//update in game loop
y2Angle += spinSpeed;
y4Angle += spinSpeed;
y5Angle += spinSpeed;
y6Angle += spinSpeed;

y[1] = centerY + radius * sin(y2Angle);
y[3] = centerY + radius * sin(y4Angle);
y[5] = centerY + radius * sin(y5Angle);
y[4] = centerY + radius * sin(y6Angle);

12
General / pseudo 3D rotation help
« on: November 18, 2008, 12:44:58 am »
So for my first game I'm making an asteroids clone and I'm trying to draw an asteroid with lines that has pseudo 3D "rotation". I'm trying to do this without getting overly complicated and just moving 4 y coords when the "z" coord is increased .2 every frame. It changes to -.2 when a y coord is at the edge of the asteroid (distance from the center is greater than radius).

The problem is I think the functions decrease slower than they increase so every 2nd rotation or so the asteroid looks fatter when all the y coords are passing each other in the center. If that makes sense. Any help would be appreciated. I left out the SFML drawing in my example, but obviously I would create lines with the x and y coords.

Code: [Select]
//init
double x[6] = {90,150,210,150,150,150};

double y[6] = {100,100,100,100,40,160};
double radius = 60;
double centerY = 100;
double spinSpeed = .2;

//in game loop
//Reverse function when halfway to simulate spin
if ((y[1] - centerY) >= radius)

    {  

        count = -spinSpeed;

    }

   

    else if ((y[1] - centerY) <= -radius)

    {

        count = spinSpeed;

    }

   

    if ((y[4] - centerY) >= radius-5)
    {  

        count2 = -spinSpeed;

    }

   

    else if ((y[4] - centerY) <= -radius)
    {  

        count2 = spinSpeed;

    }

double z2 = sqrt(y[1]) + count;
double z6 = sqrt(y[5]) - count2;

y[1] = pow(z2,2.0);
y[3] = centerY-(y[1] - centerY);
y[5] = pow(z6,2.0) ;

y[4] = centerY-(y[5] - centerY);

Pages: [1]
anything