Register    Login    Forum    Search    FAQ

Board index » Everything




Post new topic Reply to topic  [ 7 posts ] 
Author Message
 Post Posted: April 19th, 2017, 11:32 pm 
 

Joined: April 19th, 2017, 11:27 pm
Posts: 5
Hi, I recently came back to the tutorial series and decided to make a small program through the framework in VS 2017 to get back into things. It simply draws a new rectangle every time I click the mouse. However, sometimes when I click the mouse, I lose the signal from my DVI port and have to reboot the computer to get back to normal. I don't think this is expected behavior from the framework, even if some variable is writing out of bounds. Could anyone chime in maybe if there have been similar issues? Thanks.


Top 
 Profile  
Reply with quote  
 Post Posted: April 19th, 2017, 11:57 pm 
 

Joined: February 28th, 2013, 3:23 am
Posts: 2474
Location: Oklahoma, United States
Never heard of the losing video signal accept for changing screen resolutions to one that isn't supported by your monitor.

_________________
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com


Top 
 Profile  
Reply with quote  
 Post Posted: April 20th, 2017, 2:31 pm 
Site Admin
User avatar

Joined: December 31st, 2011, 4:53 pm
Posts: 3234
Location: Japan
That is a super weird one that I've not heard before either.

_________________
Chili


Top 
 Profile  
Reply with quote  
 Post Posted: April 20th, 2017, 6:06 pm 
 

Joined: April 19th, 2017, 11:27 pm
Posts: 5
Okay guys, I uninstalled and reinstalled Visual Studio and my graphics drivers. Problem appears fixed. I can only assume it was some corrupted driver or file somewhere.


Top 
 Profile  
Reply with quote  
 Post Posted: April 20th, 2017, 8:22 pm 
 

Joined: February 28th, 2013, 3:23 am
Posts: 2474
Location: Oklahoma, United States
Well, hopefully that was the issue. Welcome to the forums btw.

_________________
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com


Top 
 Profile  
Reply with quote  
 Post Posted: April 22nd, 2017, 3:40 am 
User avatar

Joined: September 14th, 2015, 10:58 pm
Posts: 27
Location: Jena
BugSquisher wrote:
It simply draws a new rectangle every time I click the mouse. .


Yes I also thought that drawing a rectangle is a simple matter. In my case it didn't cause issues for my computer but it did cause issues for my head :lol:

I tried to make a function to draw a rectangle of given height and width at given angle.
I used chili's DrawLine function (old series tutorial 10):

Code:
void Graphics::DrawLine(int x1, int y1, int x2, int y2, int r, int g, int bl)//  for elaborate explanation see old beginner series lesson 10
{
   int dx = x2 - x1;
   int dy = y2 - y1;

   if (abs(dy)>abs(dx)) { // calculates the x values relative to y - its an mirror function of the y = f(x)
      if (y1>y2) {
         int temp = y2;//swaps the values of y1 and y2 so that drawing loop gets executed for this condition
         y2 = y1;
         y1 = temp;
         temp = x2;//swaps the values of x2 and x1
         x2 = x1;
         x1 = temp;
      }

      float m = (float)dx / (float)dy; // calculates the steepness of the line
      float b = x1 - m*y1;               // calculates the y-intercept
      for (int y = y1; y <= y2; y++) {
         int x = m*y + b+ 0.5f; // 0.5f corrects the rounding effect of compiler(see video)
         PutPixel(x, y, r, g, bl);
      }
   }
   else {
      if (x1>x2) {
         int temp = y2;//swaps the values of y1 and y2 so that drawing loop gets executed for this condition(see video)
         y2 = y1;
         y1 = temp;
         temp = x2;//swaps the values of x2 and x1
         x2 = x1;
         x1 = temp;
      }

      float m = (float)dy / (float)dx; // calculates the steepness of the line
      float b = y1 - m*x1;               // calculates the y-intercept
      for (int x = x1; x <= x2; x++) {
         int y = m*x + b + 0.5f;
         PutPixel(x, y, r, g, bl);
      }
   }
}

but i was unable to draw a rectangle with single
loop - some holes and gaps get drawn because of breaking lines :x
. I use the second loop to fill them out:
Code:
void Graphics::DrawRectangle(int cx, int cy, int height, int width, int angle, int r, int g, int b)
{
   const float PI = 3.14159;
   const float ra = angle* PI / 180.0;//angle in radians
   const int hw = width / 2; //half of width
   const int hh = height / 2; //half of height


         const int Ax = cx - hw*cos(ra) - hh*sin(ra);
         const int Ay = cy - hw*sin(ra) + hh*cos(ra);

         const int Bx = cx + hw*cos(ra) - hh*sin(ra);
         const int By = cy + hw*sin(ra) + hh*cos(ra);


         const int Cx = cx - hw*cos(ra) + hh*sin(ra);
         const int Cy = cy - hw*sin(ra) - hh*cos(ra);
         
         float y1 = Ay, x2 = Cx, y2 = Cy, x1=Ax;
         for (  x1 = x1; x1 <= Bx; x1 = x1+ cos(ra)) {
            DrawLine(x1, y1, x2, y2, r, g, b);
            x2 = x2 + cos(ra);
            y1 = y1 + sin(ra);
            y2 = y2 + sin(ra);
         }

         x1 = Ax, x2 = Bx, y2 = By;
         for ( y1 = Ay; y1 >= Cy; y1 = y1 - cos(ra)) { // this loop shouldn't be necessary - it's just meant to fill out holes
            DrawLine(x1, y1, x2, y2, r, g, b);
            x1= x1 + sin(ra);
            x2 = x2 + sin(ra);
            y2 = y2 - cos(ra);
         }

I know that there are built-in functions for rotation and i try to reinvent the wheel here but maybe
someone here finds this interesting and has some tips.
Besides that it doesn't function properly if height>width or if angle>90 degrees because fucking sine is odd and cosine even.

Attachment:
rect1.png
rect1.png [ 4.93 KiB | Viewed 129 times ]

_________________
Kraut


Top 
 Profile  
Reply with quote  
 Post Posted: April 22nd, 2017, 11:55 pm 
 

Joined: February 28th, 2013, 3:23 am
Posts: 2474
Location: Oklahoma, United States
If you want to draw rects that rotate, check out chili's old Advanced tuts or his new 3D fundamentals tuts. He covers that very topic.

_________________
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com


Top 
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
 
Post new topic Reply to topic  [ 7 posts ] 

Board index » Everything


 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
cron