• Welcome to Dark Bit Factory & Gravity.
 
Menu

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.

Show posts Menu

Messages - SoldierBoy

#1
This offer is not available in your country. :(  US.

Still a great thread though.

SB
#2
Happy Birthday Jim!

You are AWESOME!!!

Thanks for all your help,
SoldierBoy
#3
For the life of me I can't figure this out.  I've read many tutorials and looked at other examples about rotation, and to be honest I'm ready to pull all my hair out. LOL

Can somebody please take a look at this and tell me what I should do to fix it?

I want to draw a star and rotate it on itself by its center.


void drawRotatedStar(buffer &buf, int centerX, int centerY, int radius, double angle, int rgb) {
line line1;
line line2;
line line3;
line line4;
line line5;

double matrix[2][2]; //Matrix of 2 * 2
double radians = angle*(PI/180);
matrix[0][0] = cos(angle);
matrix[1][0] = -sin(angle);
matrix[0][1] = sin(angle);
matrix[1][1] = cos(angle);
int oldX, oldY;

//Create our Stars
    line1.x1 = centerX;
    line1.y1 = centerY + radius;
    line1.x2 = (centerX + sin(4*PI/5) * radius);
    line1.y2 = (centerY + cos(4*PI/5) * radius);

line2.x1 = (centerX + sin(4*PI/5) * radius);
    line2.y1 = (centerY + cos(4*PI/5) * radius);
    line2.x2 = (centerX + sin(8*PI/5) * radius);
    line2.y2 = (centerY + cos(8*PI/5) * radius);

line3.x1 = (centerX + sin(8*PI/5) * radius);
    line3.y1 = (centerY + cos(8*PI/5) * radius);
    line3.x2 = (centerX + sin(2*PI/5) * radius);
    line3.y2 = (centerY + cos(2*PI/5) * radius);

line4.x1 = (centerX + sin(2*PI/5) * radius);
    line4.y1 = (centerY + cos(2*PI/5) * radius);
    line4.x2 = (centerX + sin(6*PI/5) * radius);
    line4.y2 = (centerY + cos(6*PI/5) * radius);

    line5.x1 = (centerX + sin(6*PI/5) * radius);
    line5.y1 = (centerY + cos(6*PI/5) * radius);
    line5.x2 = centerX;
    line5.y2 = centerY + radius;

//Rotate our stars
    oldX = line1.x1;
    oldY = line1.y1;
    line1.x1 = (oldX * matrix[0][0]) + (oldY * matrix[0][1]) + centerX;
    line1.y1 = (oldX * matrix[1][0]) + (oldY * matrix[1][1]) + centerY;
oldX = line1.x2;
    oldY = line1.y2;
    line1.x2 = (oldX * matrix[0][0]) + (oldY * matrix[0][1]) + centerX;
    line1.y2 = (oldX * matrix[1][0]) + (oldY * matrix[1][1]) + centerY;
oldX = line2.x1;
    oldY = line2.y1;
    line2.x1 = (oldX * matrix[0][0]) + (oldY * matrix[0][1]) + centerX;
    line2.y1 = (oldX * matrix[1][0]) + (oldY * matrix[1][1]) + centerY;
oldX = line2.x2;
    oldY = line2.y2;
    line2.x2 = (oldX * matrix[0][0]) + (oldY * matrix[0][1]) + centerX;
    line2.y2 = (oldX * matrix[1][0]) + (oldY * matrix[1][1]) + centerY;
    oldX = line3.x1;
    oldY = line3.y1;
    line3.x1 = (oldX * matrix[0][0]) + (oldY * matrix[0][1]) + centerX;
    line3.y1 = (oldX * matrix[1][0]) + (oldY * matrix[1][1]) + centerY;
    oldX = line3.x2;
    oldY = line3.y2;
    line3.x2 = (oldX * matrix[0][0]) + (oldY * matrix[0][1]) + centerX;
    line3.y2 = (oldX * matrix[1][0]) + (oldY * matrix[1][1]) + centerY;
    oldX = line4.x2;
    oldY = line4.y2;
    line4.x2 = (oldX * matrix[0][0]) + (oldY * matrix[0][1]) + centerX;
    line4.y2 = (oldX * matrix[1][0]) + (oldY * matrix[1][1]) + centerY;
    oldX = line4.x1;
    oldY = line4.y1;
    line4.x1 = (oldX * matrix[0][0]) + (oldY * matrix[0][1]) + centerX;
    line4.y1 = (oldX * matrix[1][0]) + (oldY * matrix[1][1]) + centerY;
    oldX = line5.x1;
    oldY = line5.y1;
    line5.x1 = (oldX * matrix[0][0]) + (oldY * matrix[0][1]) + centerX;
    line5.y1 = (oldX * matrix[1][0]) + (oldY * matrix[1][1]) + centerY;
oldX = line5.x2;
    oldY = line5.y2;
    line5.x2 = (oldX * matrix[0][0]) + (oldY * matrix[0][1]) + centerX;
    line5.y2 = (oldX * matrix[1][0]) + (oldY * matrix[1][1]) + centerY;

//Draw our stars
    drawLine(buf, line1.x1, line1.x2, line1.y1, line1.y2, rgb);
    drawLine(buf, line2.x1, line2.x2, line2.y1, line2.y2, rgb);
    drawLine(buf, line3.x1, line3.x2, line3.y1, line3.y2, rgb);
    drawLine(buf, line4.x1, line4.x2, line4.y1, line4.y2, rgb);
    drawLine(buf, line5.x1, line5.x2, line5.y1, line5.y2, rgb);

}



Thanks in advance!  I plan on release the sourcecode to this little demo when I'm done.
#4
Freebasic / Re: Gear Wheels
September 22, 2007
What a fine release Shockwave!

I'm amazed that you release your source for everyone to see.

Thanks for sharing!  This is truly the only place on the internet to learn Demo coding

And get help from such knowledgeable people!


k++

SoldierBoy/ICC2007
Infinity 1987-2007

#5
C / C++ /C# / Re: C++ loading PNG files
September 04, 2007
Thanks for the Karma guys!

I take no credit for the code, its just some random shit that Google found.

But thanks for Sean Barrett for the public domain code that we can all use.

Look for more from me, when I get these Pixels Toasting.....

SoldierBoy/ICC 2007

#6
Helps if I actually attach the damn file...

Here it is.

SB/ICC207

#7
Thanks for everybody's help!

Jim, nenogenio, va!n, chris

Thanks guys, I'm going to look at both of those options!

Thanks again.

This is how I ended up doing it:
included this file into my project: http://nothings.org/stb_image.c

and wrote this function to load a .png and put into my buffer:


bool loadPNG( std::string filename,  int & width, int & height, int &bitdepth, vector<Pixel> & pixels){

unsigned int index = 0;

unsigned char *data = stbi_load((char *)filename.c_str(), &width, &height, &bitdepth, 0);
if (!data) return false;
// convert 24 bit image pixels to floating point color

pixels.resize( width * height );

for ( int y = 0; y < height; ++y )
{
for ( int x = 0; x < width; ++x )
{
Pixel & pixel = pixels[index];

pixel.r = data[index*3+0] * 1.0f / 255.0f;
pixel.g = data[index*3+1] * 1.0f / 255.0f;
pixel.b = data[index*3+2] * 1.0f / 255.0f;
pixel.a = data[index*3+3] * 1.0f / 255.0f;

++index;

}
}

return true;
}




I've attatched the stb_image.c file to this post.  Maybe it will of some use to others....

Thanks!
SoldierBoy/ICC2007

#8
Thanks Jim!  I was hoping you would reply! :)  And thank you for the welcome back.....

I was really hoping that someone had just a complete source file for reading, but oh well. :)

I initially went the libpng route, and even found a C++ wrapper for it, but then again, it was incomplete.....

Even just using libpng, seemed overtly complex. 

And the ultimate goal of this is to have 1 file exe, which seems to be the latest rage around here.

I'm not in this to make a 1k or 4k....haha.....so I don't really care about filesize too much.

I just want the cleanliness(???) of it all.

My job brought me into this C++ world.  So I thought I would try and bring C++ into my demo (hobby) world....hahaha

But I tell you what, its so tempting to jump into the FREEBASIC world, since even it has pnglib includes and samples.....

I'll most definately be checking out that source you posted.

Thank you!
SoldierBoy/ICC 1995-2007
Even non-Legends Live On!

#9
Freebasic / Re: Gear Wheels
August 30, 2007
Shockwave, your productions are always amazing!

Can't wait to see this released!

SoldierBoy
#10
ok, I've searched and searched and searched....and have yet to find a clean, usable, C++ PNG reader!!!!

What does everyone here use to load images in?

I'm really seeking just something easy.  Something that doesn't have a huge library attatched to it.

I'm using PixelToaster for my display buffer.  I'm happy with my performance at the moment, but want to do some additional testing.

HELP please? :)

BTW, I was a member here years ago....Hello Shockwave and Clyde and Everyone else!!!
SoldierBoy/ICC2007
Infinity Never Returned haha