2d Bitmap rotation under DirectDraw

Started by
24 comments, last by SpazBoy the Mitey 22 years, 1 month ago
Hopefully you''ll get it to work.

I uploaded my demo at GD.net to give you hope
(if it runs) heh

It uses the same rotation function as I posted, altough the
one I posted could include bugs because I tried to use it again but had some troubles. But here''s one that should work I coped from a working backup of my wrapper:

  //-----------------------------------------------------------------------------// Name: RotateBlit// Desc: Rotates and blits a surface//-----------------------------------------------------------------------------WorkSurface::RotateBlit(int x, int y, float alpha, SURFACEDATA Scr, 						bool ColorKey){	DDSURFACEDESC2		SurfaceDesc2;	DDCOLORKEY			ddck;		int					lPitch2;	USHORT*				Buffer2;		int ux,uy,vv;	float hw,hh,x1,y1,x2,y2,x3,y3,mx,my,mx2,my2,ty,ty2,rx,ry,alpha2,r;		alpha = alpha * (2.0f*PI/360.0f);	hw=Scr.Width/2.0f;	hh=Scr.Height/2.0f; 	//ColorKey	Scr.Surface->GetColorKey(DDCKEY_SRCBLT, &ddck);	//Locks the destination surface	INITDESC(SurfaceDesc2);	SurfaceData.Surface->Lock(NULL, &SurfaceDesc2, DDLOCK_SURFACEMEMORYPTR |						        DDLOCK_WAIT, NULL);	Buffer=(USHORT *)SurfaceDesc2.lpSurface;	lPitch=(int)(SurfaceDesc2.lPitch >> 1);	//Locks the source surface	INITDESC(SurfaceDesc2);	Scr.Surface->Lock(NULL, &SurfaceDesc2, DDLOCK_SURFACEMEMORYPTR |						        DDLOCK_WAIT, NULL);	Buffer2=(USHORT *)SurfaceDesc2.lpSurface;	lPitch2=(int)(SurfaceDesc2.lPitch >> 1);		//radien	r=sqrtf(hw*hw+hh*hh);	// #1 /*	ux=-hw;	uy=-hh;*/ 	alpha2=-(acosf(-hw/r))+alpha; 	x1=(x+cosf(alpha2)*r);	y1=(y+sinf(alpha2)*r); 		// #2	alpha2=-(acosf(-hw/r))+alpha; 	x2=(x+cosf(alpha2)*r);	y2=(y+sinf(alpha2)*r); 		// #3	alpha2=acosf(hw/r)+alpha; 	x3=(x+cosf(alpha2)*r);	y3=(y+sinf(alpha2)*r); 	mx=(x2-x1)/(Scr.Width);	my=(y2-y1)/(Scr.Width);	mx2=(x3-x2)/(Scr.Height);	my2=(y3-y2)/(Scr.Height);	for(uy=0;uy<Scr.Height;uy++){		ty=(uy*mx2);		ty2=(uy*my2);		rx=x1;		ry=y1;    	for(ux=0;ux<Scr.Width;ux++){			rx+=mx;			ry+=my;			if(Buffer2[ux+uy*lPitch2] != ddck.dwColorSpaceLowValue)			{			vv=int(rx+ty)+int(ry+ty2)*lPitch; 			Buffer[vv]=Buffer2[ux+uy*lPitch2];			Buffer[vv+1]=Buffer2[ux+uy*lPitch2];			}	}}	Scr.Surface->Unlock(NULL);	SurfaceData.Surface->Unlock(NULL);}  


And my cool demo is here:
2D SOFTWARE ROOTATION IN DIRECTDRAW DEMO

Good luck all!!

/MindWipe

"If it doesn''t fit, force it; if it breaks, it needed replacement anyway."
"To some its a six-pack, to me it's a support group."
Advertisement
The demo is here now! What are you waiting for?

/MindWipe

"If it doesn''t fit, force it; if it breaks, it needed replacement anyway."
"To some its a six-pack, to me it's a support group."
yeah its okies for 1 bitmap rotated at a time, but when you need 30...

nice demo though, heres my stats:

PIII 450
Windows 2000
128MB RAM
INTEL i740 VIDEO CARD

320x240: 169 fps
640x480: 60 fps

I think you should write that tutorial
I''m not interested, really.
True... but it''s unoptimized and you could speed things up by locking once and lotsa other small optimizations.

And the beginning code of the demo is also a bit dumb. You could play around with vmem/smem and stuff like that. And it also contains a GetDC and TextOut.

But I fear it''s not possible to do too many miracles in ddraw
making a loop that fills the screen is slow only about 50 fps can be received

Still, good luck!



/MindWipe

"If it doesn''t fit, force it; if it breaks, it needed replacement anyway."
"To some its a six-pack, to me it's a support group."
Do all of these clip?
If found clipping the biggest stumbling block in this and so I stopped my attempt when I couldn''t figure out a nice easy way to do it.
Clip? It couldn''t be hard to do.. or what do you mean? Clip so that it doesn''t draw x < 0 etc? what''s hard about that?

/MindWipe

"If it doesn''t fit, force it; if it breaks, it needed replacement anyway."
"To some its a six-pack, to me it's a support group."

This topic is closed to new replies.

Advertisement