Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


2D Line Rotation

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
Nigtronix
Cheater
Reputation: 0

Joined: 18 May 2007
Posts: 45

PostPosted: Wed May 23, 2007 2:11 am    Post subject: 2D Line Rotation Reply with quote

Hey, I'm trying to make something like the second hand on an analog wall clock. I want a solid line to rotate from the center of the screen, 360 degrees.

Below is my attempt(SIMPLIFIED): (But it isn't working correctly)

Code:

/*************************************************************************************
   RADAR_ME - An almost pointless program that tries to emulate a real radar or sonar
   screen.

   This version is conceptional version, that draws the radar to Device Context(0), or
   the current global screen(desktop).


   Author: NigTronIX
   
   Date concepted: May 23, 2007 @ 12:07AM, Thanks rewt for the project idea ^^

   Last Modified: May 23, 2007 @ 2:07AM

   TODO: Threading optimizations, Transparent window, lighting effects or something
   
         - Move all Function declarations in header file after coding window code

        I don't know, but I think my line drawing functions need optimized also ;P

      Thanks to my math book for rotating line formula!

   Compiled using Microsoft Visual C++ 6.0 under Windows XP Home SP1
             
            



***************************************************************************************/

#include <windows.h>
#include <conio.h> //debugging
#include <math.h>
#include <stdlib.h>
#include <stdio.h> //debugging
#include <time.h>
/* Global Constants */

#define DCON 0 // Device context to use

#define DegToRad 0.017453293f

/* Prototypes ^^ */

int Draw_line(); // returns 0 on failure, USED LATER
int Get_Center_Of_Screen(int *x, int *y); // returns 0 on failure, USED LATER

int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd )
{
   
   /* Get Center of Screen */

   int cx = GetSystemMetrics(SM_CXSCREEN);
    int cy = GetSystemMetrics(SM_CYSCREEN);
    int pos1= cx / 2;
    int pos2= cy / 2;
   HDC hwnd = GetDC(DCON);
   int T = 1;

   while(1)
   {
       
        for(; T <= 60; T++) {

         SetPixel(hwnd,(cos(T) * pos1) - (sin(T) * pos2), (sin(T) * pos1) + (cos(T) * pos2) ,RGB(255,0,0));
         Sleep(1);
      }

      T = 1; // reset

   }




   return 0;
}



UPDATE: I now have it operating ALMOST the way I want it: but I want it to show only one line not multiple lines

Code:

   /* Get Center of Screen */

   int cx = GetSystemMetrics(SM_CXSCREEN);
    int cy = GetSystemMetrics(SM_CYSCREEN);
    int pos1= cx / 2;
    int pos2= cy / 2;
   HDC hwnd = GetDC(DCON);

   // General forumula: X =  X_Origin + cos(angle) * radius
   // Radius is the line length
   // Y = Y_Origin + sin(angle) * radius

   SaveDC(hwnd);

   while(1)
   {
       
        for(int T = 1; T <= (10); T++) {

         MoveToEx(hwnd, pos1, pos2, NULL); // update current brush  to origin
         LineTo(hwnd,pos1 + cos(T) * 200, pos2 + sin(T) * 200);
         RestoreDC(hwnd,1);

         Sleep(5);
         SaveDC(hwnd);
      }


   }


I'm trying to use SaveDC() and RestoreDC() to erase the lines before the new line is redrawn o.o

It's not working Sad

Any help will be appreicated thanks Very Happy, also anybody know how to specify line color,width, and length?


thanks
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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 vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites