Results 1 to 7 of 7

Thread: Drawing skewed images

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Oct 2004
    Posts
    68

    Drawing skewed images

    Is there any function that lets me specify the 4 points of a bitmap. The skewed drawimage function doesn't work cause I want an effect where the corners can be anywhere.

  2. #2
    Not NoteMe SLH's Avatar
    Join Date
    Mar 2002
    Location
    192.168.0.1 Preferred Animal: Penguin Reason for errors: Line#38
    Posts
    3,051

    Re: Drawing skewed images

    I'm not sure if such a function exists in the language that you are using, however many articles regarding texture mapping at www.gamedev.net are relevent to what you want to do.

    Let me know if you hit a dead end, or can't find anything helpfull there.
    Quotes:
    "I am getting better then you guys.." NoteMe, on his leet english skills.
    "And I am going to meat her again later on tonight." NoteMe
    "I think you should change your name to QuoteMe" Shaggy Hiker, regarding NoteMe
    "my sweet lord jesus. I've decided never to have breast implants" Tom Gibbons
    Have I helped you? Please Rate my posts.


  3. #3
    Elite Hacker Jacob Roman's Avatar
    Join Date
    Aug 2004
    Location
    Miami Beach, FL
    Posts
    5,349

    Re: Drawing skewed images

    That can easily be done on DirectX and OpenGL. Don't rely on slow and limited functions like DrawImage. http://nehe.gamedev.net (goto OpenGL Tutorials located on the left) and www.gametutorials.com (Click on the tutorials button and pick either OpenGL or DirectX) has plenty of tutorials and source code on DX and OpenGL.

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Oct 2004
    Posts
    68

    Re: Drawing skewed images

    I wanted to do this manually first to get the idea and practice down, then I will use DX to do it for me. I'm having troubles. It seems as if we need to draw the image horizontal line by line, and skiping pixels to give depth and stretching pixels the closer to the camera we are. Am I on the right track?

  5. #5
    Not NoteMe SLH's Avatar
    Join Date
    Mar 2002
    Location
    192.168.0.1 Preferred Animal: Penguin Reason for errors: Line#38
    Posts
    3,051

    Re: Drawing skewed images

    Quote Originally Posted by RickP
    I wanted to do this manually first to get the idea and practice down, then I will use DX to do it for me. I'm having troubles. It seems as if we need to draw the image horizontal line by line, and skiping pixels to give depth and stretching pixels the closer to the camera we are. Am I on the right track?
    Yep, that's correct.
    Quotes:
    "I am getting better then you guys.." NoteMe, on his leet english skills.
    "And I am going to meat her again later on tonight." NoteMe
    "I think you should change your name to QuoteMe" Shaggy Hiker, regarding NoteMe
    "my sweet lord jesus. I've decided never to have breast implants" Tom Gibbons
    Have I helped you? Please Rate my posts.


  6. #6

    Thread Starter
    Lively Member
    Join Date
    Oct 2004
    Posts
    68

    Re: Drawing skewed images

    Now how does 1 go about doing that?

  7. #7
    Not NoteMe SLH's Avatar
    Join Date
    Mar 2002
    Location
    192.168.0.1 Preferred Animal: Penguin Reason for errors: Line#38
    Posts
    3,051

    Re: Drawing skewed images

    The first think i suggest you get working is being able to fill a triangle with a colour.

    To do this you need to arrange the points from lowest Y coord to highest.

    Then you need to get the gradient for each edge of the triangle.

    Once you've done that you can calculate a scan-line. This is a horizontal line that you can fill in, to draw part of the triangle.

    I don't really have time to explain it all but here's how i get the scan-lines:
    Code:
    //Order the coordinates correctly
    	if(y1 < y0)
    	{
    		dt = y0; y0 = y1; y1 = dt;
    		dt = x0; x0 = x1; x1 = dt;
    	}
    	if(y2 < y1)
    	{
    		dt = y1; y1 = y2; y2 = dt;
    		dt = x1; x1 = x2; x2 = dt;
    	}
    	if(y2 < y0)
    	{
    		dt = y0; y0 = y2; y2 = dt;
    		dt = x0; x0 = x2; x2 = dt;
    	}
    	if(y1 < y0)
    	{
    		dt = y0; y0 = y1; y1 = dt;
    		dt = x0; x0 = x1; x1 = dt;
    	}
    	dx0 = x1 - x0;
    	dy0 = y1 - y0;
    
    	dx1 = x2 - x1;
    	dy1 = y2 - y1;
    
    	dx2 = x0 - x2;
    	dy2 = y0 - y2;
    	//Calculate gradients
    	if(dy0 != 0)
    		Gradient0 = dx0 / dy0;
    	else
    		Gradient0 = 0;
    
    	if(dy1 != 0)
    		Gradient1 = dx1 / dy1;
    	else
    		Gradient1 = 0;
    
    	if(dy2 != 0)
    		Gradient2 = dx2 / dy2;
    	else
    		Gradient2 = 0;
    
    	double sx,ex;
    	
    	double id;
    	if(CurrentMultiFrameNumber == 1)
    		cout << "Frame #" << FrameNumber << " RENDERING POLYGON" << endl;
    
    	//Step through each line in the triangle, working out the scanline, then call the scanline rendering function
    	for(i = (int) y0; i < y1; i++)
    	{
    		id = (double) i;
    
    		sx = (x0 + ((id - y0) * Gradient2));
    		ex = (x0 + ((id - y0) * Gradient0));
    		
    		if(sx < ex)
    			RenderScanLine(pImage,Triangle,sx,i,ex - sx, pTexture, AlphaBlend);
    		else
    			RenderScanLine(pImage,Triangle,ex,i,sx - ex, pTexture, AlphaBlend);
    	}
    
    	for(i = (int) y1; i < y2; i++)
    	{
    		sx = (x0 + ((i - y0) * Gradient2));
    		ex = (x1 + ((i - y1) * Gradient1));
    		
    		if(sx < ex)
    			RenderScanLine(pImage,Triangle,sx,i,ex - sx, pTexture, AlphaBlend);
    		else
    			RenderScanLine(pImage,Triangle,ex,i,sx - ex, pTexture, AlphaBlend);
    	}
    To begin with just make your renderscanline function loop through each pixel in the line, using the same colour, ust to test whether it works.
    Quotes:
    "I am getting better then you guys.." NoteMe, on his leet english skills.
    "And I am going to meat her again later on tonight." NoteMe
    "I think you should change your name to QuoteMe" Shaggy Hiker, regarding NoteMe
    "my sweet lord jesus. I've decided never to have breast implants" Tom Gibbons
    Have I helped you? Please Rate my posts.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width