[UPDATE] AVRO 0.2.9 - The Jet Fighter Game. TheToddfather

The Partridge Family were neither partridges nor a family. Discuss.
User avatar
thetoddfather
Posts: 338
Joined: October 1st, 2012, 9:53 pm
Location: Canada

Re: Avro 0.1.1 - Jet Fighter Game. Sprite Rotation/Scaling.

Post by thetoddfather » November 30th, 2013, 8:14 am

Not at this time chili. Working on something similar to the rotsprite scaling predictions to attempt it, but for now it's 1x and below. But the bullets are drawn using the same algorithms to keep scale and angles as well. They just move too fast to be able to really see it. But yes, these were not copied from some other project. Written directly into the framework, with a good many days of frustration before payoff lol

User avatar
LuX
Posts: 1492
Joined: April 22nd, 2012, 12:33 pm
Location: Finland

Re: Avro 0.1.1 - Jet Fighter Game. Sprite Rotation/Scaling.

Post by LuX » November 30th, 2013, 5:57 pm

Oh nice you programmed the rotation yourself. Assuming you just rotate for each pixel, how did you cover the empty holes? Calculated the average value of surrounding pixels?
ʕ •ᴥ•ʔ

User avatar
thetoddfather
Posts: 338
Joined: October 1st, 2012, 9:53 pm
Location: Canada

Re: Avro 0.1.1 - Jet Fighter Game. Sprite Rotation/Scaling.

Post by thetoddfather » November 30th, 2013, 7:48 pm

Well Lux, I wanted to do a predictor algorithm similar to one in a brilliant little program called rotsprite. Bout the best out there for scaling/rotating. And he's explained to people 'how' he did it, but the source isn't available to see. Tried a few things along the lines you're describing. Nothing looked good. So for now, 1X has artifacts, so the sprites are simply using the pixel translations and then scaled down. All artifacts are gone about .8x. Figure I'm decent at phototshop, so I'll boost my graphics a little in size till I want to really sit down and write something I can be happy with the result of. But yah, that's sorta the ideas I see floating around. Find the averages and what not. For now I wanted to get the game functioning so I'm happy with the way it functioned. Few months ago I didn't think I'd ever have real-time rotation from the center of a sprite looking anywhere near this good in my games, so gotta be happy with that anyway, haha

User avatar
chili
Site Admin
Posts: 3948
Joined: December 31st, 2011, 4:53 pm
Location: Japan
Contact:

Re: Avro 0.1.1 - Jet Fighter Game. Sprite Rotation/Scaling.

Post by chili » December 2nd, 2013, 2:48 am

Gnarly, I'm sure you guys will appreciate the thing the stuff we are going to cover after the platformer is taken care of.

Basically, the way you end up doing rotation and scaling is different than what people usually do on their first try. Most people start at the source image, loop through each pixel, transform it to its position in the destination, and then set it in the destination. This results in holes.

The way you actually do it is you start at the destination by 'making' a rectangle there which has the same dimensions as the source, transforming it so that it has the desired rotation and scaling, then looping through every pixel inside the transformed destination rectangle and reversing the transformation to arrive at the corresponding pixel in the source image by rounding. This will get you 'nearest neighbor' interpolation. More visual appealing results can be achieved by, instead of just rounding to the closest pixel and using it, taking a weighted sum of the pixels which surround the actual inverse-transformed point. This is called bilinear interpolation.
Chili

Mr_Someguy
Posts: 1
Joined: December 2nd, 2013, 3:40 am

Re: Avro 0.1.1 - Jet Fighter Game. Sprite Rotation/Scaling.

Post by Mr_Someguy » December 2nd, 2013, 3:43 am

Most impressive! I have actually been.... 'Stalking' around the forums and been seeing your helpful nature thetoddfather and I think you're doing great work. This inspired me to get an account just to reply. :P

User avatar
thetoddfather
Posts: 338
Joined: October 1st, 2012, 9:53 pm
Location: Canada

Re: Avro 0.1.1 - Jet Fighter Game. Sprite Rotation/Scaling.

Post by thetoddfather » December 2nd, 2013, 4:58 am

Chili,

Well isn't that just a teaser from hell! Feel free to drop some code randomly into my lap to see how that's done. I have noticed doing it this way does have a tax on your framerate. Which, when you've got six planes in a dog fight, adds up. Your way sounds less taxing and now I am salivating! Must... Make... Perfect...

Mr_Someguy,
That means a lot man. Seriously. I love this stuff and I love when people are excited about my creations and making their own creations. But seriously, thanks. Are you working on the series? We going to have a game by you one of these days?

User avatar
LuX
Posts: 1492
Joined: April 22nd, 2012, 12:33 pm
Location: Finland

Re: Avro 0.1.1 - Jet Fighter Game. Sprite Rotation/Scaling.

Post by LuX » December 2nd, 2013, 2:48 pm

Or for the best results just use directx to handle everything I guess. At the same time I once was tempted to make a pixel art game where I make all the graphical things like drawing, rotating and what not from scratch myself, but the easiness of directx was more tempting than that. It's always nice to make some existing functions yourself even at the cost of performance, just to better understand what's happening, and to be able to truly call it "mine".
ʕ •ᴥ•ʔ

Natories
Posts: 107
Joined: June 21st, 2012, 7:06 am
Location: USA
Contact:

Re: Avro 0.1.1 - Jet Fighter Game. Sprite Rotation/Scaling.

Post by Natories » December 2nd, 2013, 3:40 pm

I've been working on a game for several months now, off and on, that uses the GDI to rotate images. I found it on the internet and had to do some minor tweaks to get it to work with my program. I am not sure if it will work on every system because of this line of code 'SetGraphicsMode(destinationDC, GM_ADVANCED);' but I thought I'd share it anyway.
Here is the modified function:

Code: Select all

HBITMAP RotateSprite(HBITMAP hBitmap, float fRadians, COLORREF clrBack)
{
            // Create a memory DC compatible with the display
	HDC sourceDC, destinationDC;
	sourceDC = CreateCompatibleDC(GetDC(_pGame->GetWindow()));
	destinationDC = CreateCompatibleDC(GetDC(_pGame->GetWindow()));
	
	// Get logical coordinates
	BITMAP bm;
	GetObject(hBitmap, sizeof(bm), &bm); 	
	float fCosine = (float)cos(fRadians);
	float fSine   = (float)sin(fRadians);

	// Compute dimensions of the resulting bitmap
	// First, get the coordinates of the 3 corners other than origin
	int x1 = (int)(bm.bmHeight * fSine);
	int y1 = (int)(bm.bmHeight * fCosine);
	int x2 = (int)(bm.bmWidth * fCosine + bm.bmHeight * fSine);
	int y2 = (int)(bm.bmHeight * fCosine - bm.bmWidth * fSine);
	int x3 = (int)(bm.bmWidth * fCosine);
	int y3 = (int)(-bm.bmWidth * fSine);

	int minX = min(0, min(x1, min(x2, x3)));
	int minY = min(0, min(y1, min(y2, y3)));
	int maxX = max(0, max(x1, max(x2, x3)));
	int maxY = max(0, max(y1, max(y2, y3)));

	int w = maxX - minX;
	int h = maxY - minY;

	// Create a bitmap to hold the result
	HBITMAP hbmResult = CreateCompatibleBitmap(GetDC(_pGame->GetWindow()), w, h);
	HBITMAP hbmOldSource = (HBITMAP)SelectObject(sourceDC, hBitmap);
	HBITMAP hbmOldDestination = (HBITMAP)SelectObject(destinationDC, hbmResult);

	// Draw the background color before we change mapping mode
	HBRUSH hbrBack = CreateSolidBrush(clrBack);
	HBRUSH hbrOld = (HBRUSH)SelectObject(destinationDC, hbrBack);
	PatBlt(destinationDC, 0, 0, w, h, PATCOPY);
	DeleteObject(SelectObject(destinationDC, hbrOld));

	// We will use world transform to rotate the bitmap
	SetGraphicsMode(destinationDC, GM_ADVANCED);
	XFORM xform;
	xform.eM11 = fCosine;
	xform.eM12 = -fSine;
	xform.eM21 = fSine;
	xform.eM22 = fCosine;
	xform.eDx = (float)-minX;
	xform.eDy = (float)-minY;

	SetWorldTransform(destinationDC, &xform);

	// Now do the actual rotating - a pixel at a time
	BitBlt(destinationDC,0,0,bm.bmWidth,bm.bmHeight,sourceDC,0,0,SRCCOPY);

	// Restore DCs
	SelectObject(sourceDC, hbmOldSource);
	SelectObject(destinationDC, hbmOldDestination);

	return hbmResult;
}
Natories

User avatar
thetoddfather
Posts: 338
Joined: October 1st, 2012, 9:53 pm
Location: Canada

Re: Avro 0.1.2 - Jet Fighter Game. [UPDATE]Dec. 2

Post by thetoddfather » December 2nd, 2013, 10:55 pm

Looks nice Nantories. Haven't tried it out yet but I might try and throw that into the engine and see how it performs.

New version up. 1st layer of terrain is in and working.

Natories
Posts: 107
Joined: June 21st, 2012, 7:06 am
Location: USA
Contact:

Re: Avro 0.1.2 - Jet Fighter Game. [UPDATE]Dec. 2

Post by Natories » December 3rd, 2013, 12:35 am

ToddFather, it works really well for the game I'm making so I hope it will work nicely for you. The way I have it set up is it rotates on the top-left corner, but it can be easily adjusted to use the center as the point of rotation.

Post Reply