Click here to Skip to main content
15,867,860 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: [win32] sprite error ? Pin
bluatigro2-Nov-17 0:13
bluatigro2-Nov-17 0:13 
GeneralRe: [win32] sprite error ? Pin
bluatigro2-Nov-17 1:01
bluatigro2-Nov-17 1:01 
GeneralRe: [win32] sprite error ? Pin
Richard MacCutchan2-Nov-17 1:46
mveRichard MacCutchan2-Nov-17 1:46 
GeneralRe: [win32] sprite error ? Pin
bluatigro3-Nov-17 0:09
bluatigro3-Nov-17 0:09 
GeneralRe: [win32] sprite error ? Pin
Richard MacCutchan3-Nov-17 0:28
mveRichard MacCutchan3-Nov-17 0:28 
GeneralRe: [win32] sprite error ? Pin
bluatigro7-Nov-17 22:36
bluatigro7-Nov-17 22:36 
GeneralRe: [win32] sprite error ? Pin
Richard MacCutchan7-Nov-17 22:45
mveRichard MacCutchan7-Nov-17 22:45 
Question[win32] VR double buffering ? Pin
bluatigro31-Oct-17 4:24
bluatigro31-Oct-17 4:24 
i m trying as coding exersise
a verry simple VR system

error :
the picture isn't Always right
// bluatigro 31 okt 2017
// win triangle
#if defined(UNICODE) && !defined(_UNICODE)
    #define _UNICODE
#elif defined(_UNICODE) && !defined(UNICODE)
    #define UNICODE
#endif

#include <tchar.h>
#include <windows.h>
#include <vector>
#include <math.h>
int winx , winy ;
class d3d
{
public :
  double x , y , z ;
  d3d()
  {
    x = 0.0 ;
    y = 0.0 ;
    z = 0.0 ;
  }
  d3d( double a , double b , double c )
  {
    x = a ;
    y = b ;
    z = c ;
  }
} ;
d3d operator + ( d3d a , d3d b )
{
  return d3d( a.x+b.x,a.y+b.y,a.z+b.z) ;
}
d3d operator / ( d3d a , double b )
{
  return d3d( a.x/b,a.y/b,a.z/b) ;
}
d3d pnt[256] ;
void setpoint( int no ,
               double a ,
               double b ,
               double c )
{
  pnt[ no ] = d3d(a,b,c) ;
}
class triangle
{
public :
  d3d punt[ 3 ] , mid ;
  COLORREF color ;
  triangle()
  {
    ;
  }
  triangle( d3d p1 , d3d p2 , d3d p3 ,
           COLORREF kl )
  {
    punt[ 0 ] = p1 ;
    punt[ 1 ] = p2 ;
    punt[ 2 ] = p3 ;
    mid = ( p1 + p2 + p3 ) / 3 ;
    color = kl ;
  }
  void show( HDC hdc )
  {
    POINT p[ 3 ] ;
    int i ;
    if ( mid.z > -900)
    {
      for ( i = 0 ; i < 3 ; i++ )
      {

        p[i].x=(LONG)(winx/2+punt[i].x/
                    (punt[i].z+1000.0)*1000) ;
        p[i].y=(LONG)(winy/2-punt[i].y/
                    (punt[i].z+1000.0)*1000) ;
      }
      HBRUSH brush = CreateSolidBrush( color ) ;
      HPEN pen = CreatePen( PS_SOLID , 0 , color ) ;
      SelectObject( hdc , pen ) ;
      SelectObject( hdc , brush ) ;

      Polygon( hdc , p , 3 ) ;

      SelectObject( hdc , pen ) ;
      DeleteObject( pen ) ;
      SelectObject( hdc , brush ) ;
      DeleteObject( brush ) ;
    } // end if mid.z > -900
  }
} ;
const COLORREF red = RGB( 255 , 0 , 0 ) ;
const COLORREF green = RGB( 0 , 255 , 0 ) ;
const COLORREF yellow = RGB( 255 , 255 , 0 ) ;
const COLORREF blue = RGB( 0 , 0 , 255 ) ;
const COLORREF magenta = RGB( 255 , 0 , 255 ) ;
const COLORREF cyan = RGB( 0 , 255 , 255 ) ;

bool key[ 256 ] ;
triangle triangles[100] ;
int tritel ;
#define FRAME_TIMER 1
void show_al( HDC hdc )
{
  int i , j ;
  triangle h ;
  for ( i = 1 ; i < tritel ; i++ )
  {
    for ( j = 0 ; j < i - 1 ; j++ )
    {
      if ( triangles[i].mid.z
         > triangles[j].mid.z )
      {
        h = triangles[i] ;
        triangles[i] = triangles[j] ;
        triangles[j] = h ;
      }
    }
  }
  for ( i = 0 ; i < tritel ; i++ )
    triangles[i].show( hdc ) ;
}
void tri( int p1 , int p2 , int p3 , COLORREF kl )
{
  if ( tritel >= 100 ) return ;
  triangles[ tritel ] = triangle(pnt[p1],
                                 pnt[p2],
                                 pnt[p3],
                                 kl) ;
  tritel++ ;
}
void quad( int p1 , int p2 , int p3 , int p4
          , COLORREF kl )
{
  d3d p = ( pnt[p1]+pnt[p2]+pnt[p3]+pnt[p4])/4;
  setpoint( 255 , p.x,p.y,p.z ) ;
  tri( 255 , p1 , p2 , kl ) ;
  tri( 255 , p2 , p3 , kl ) ;
  tri( 255 , p3 , p4 , kl ) ;
  tri( 255 , p4 , p1 , kl ) ;
}
d3d rotatey( d3d a , double b )
{
  double s = sin( b ) , c = cos( b ) , x , z ;
  x = c * a.x - s * a.z ;
  z = s * a.x + c * a.z ;
  return d3d( x , a.y , z ) ;
}
triangle roty( triangle t , double b )
{
  t.mid = rotatey( t.mid , b ) ;
  t.punt[2] = rotatey( t.punt[2] , b ) ;
  t.punt[1] = rotatey( t.punt[1] , b ) ;
  t.punt[0] = rotatey( t.punt[0] , b ) ;
  return t ;
}
/*  Declare Windows procedure  */
LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);

/*  Make the class name into a global variable  */
TCHAR szClassName[ ] = _T("CodeBlocksWindowsApp");

int WINAPI WinMain (HINSTANCE hThisInstance,
                     HINSTANCE hPrevInstance,
                     LPSTR lpszArgument,
                     int nCmdShow)
{
    HWND hwnd;               /* This is the handle for our window */
    MSG messages;            /* Here messages to the application are saved */
    WNDCLASSEX wincl;        /* Data structure for the windowclass */

    /* The Window structure */
    wincl.hInstance = hThisInstance;
    wincl.lpszClassName = szClassName;
    wincl.lpfnWndProc = WindowProcedure;      /* This function is called by windows */
    wincl.style = CS_DBLCLKS;                 /* Catch double-clicks */
    wincl.cbSize = sizeof (WNDCLASSEX);

    /* Use default icon and mouse-pointer */
    wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
    wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
    wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
    wincl.lpszMenuName = NULL;                 /* No menu */
    wincl.cbClsExtra = 0;                      /* No extra bytes after the window class */
    wincl.cbWndExtra = 0;                      /* structure or the window instance */
    /* Use Windows's default colour as the background of the window */
    wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND;

    /* Register the window class, and if it fails quit the program */
    if (!RegisterClassEx (&wincl))
        return 0;

    /* The class is registered, let's create the program*/
    hwnd = CreateWindowEx (
           0,                   /* Extended possibilites for variation */
           szClassName,         /* Classname */
           _T("Rotating cube 1.0"),       /* Title Text */
           WS_OVERLAPPEDWINDOW, /* default window */
           CW_USEDEFAULT,       /* Windows decides the position */
           CW_USEDEFAULT,       /* where the window ends up on the screen */
           800,                 /* The programs width */
           600,                 /* and height in pixels */
           HWND_DESKTOP,        /* The window is a child-window to desktop */
           NULL,                /* No menu */
           hThisInstance,       /* Program Instance handler */
           NULL                 /* No Window Creation data */
           );

    /* Make the window visible on the screen */
    ShowWindow (hwnd, nCmdShow);

    /* Run the message loop. It will run until GetMessage() returns 0 */
    while (GetMessage (&messages, NULL, 0, 0))
    {
        /* Translate virtual-key messages into character messages */
        TranslateMessage(&messages);
        /* Send message to WindowProcedure */
        DispatchMessage(&messages);
    }

    /* The program return-value is 0 - The value that PostQuitMessage() gave */
    return messages.wParam;
}


/*  This function is called by the Windows function DispatchMessage()  */

LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
  int t ;
  PAINTSTRUCT paint ;
  HDC hdc ;
  RECT rect ;
  GetClientRect( hwnd , &rect ) ;
  switch (message)                  /* handle the messages */
  {
    case WM_CREATE :
      tritel = 0 ;
      setpoint( 0 , 100 , 100 , 100 ) ;
      setpoint( 1 , 100 , 100 , -100 ) ;
      setpoint( 2 , 100 , -100 , 100 ) ;
      setpoint( 3 , 100 , -100 , -100 ) ;
      setpoint( 4 , -100 , 100 , 100 ) ;
      setpoint( 5 , -100 , 100 , -100 ) ;
      setpoint( 6 , -100 , -100 , 100 ) ;
      setpoint( 7 , -100 , -100 , -100 ) ;
      quad( 0 , 1 , 3 , 2 , red ) ;
      quad( 7 , 6 , 4 , 5 , cyan ) ;
      quad( 0 , 1 , 5 , 4 , green ) ;
      quad( 7 , 6 , 2 , 3 , magenta ) ;
      quad( 0 , 2 , 6 , 4 , blue ) ;
      quad( 7 , 5 , 1 , 3 , yellow ) ;
      SetTimer(hwnd,FRAME_TIMER,40,NULL) ;
      break ;
    case WM_TIMER :
      if ( wParam == FRAME_TIMER )
      {
        for ( t = 0 ; t < tritel ; t++ )
        {
          triangles[t] = roty(triangles[t],.1);
        }
        InvalidateRect( hwnd , NULL , true ) ;
      }
      break ;
    case WM_KEYDOWN :
      if ( wParam == VK_ESCAPE )
        PostQuitMessage( 0 ) ;
      break ;
    case WM_PAINT :
      GetClientRect( hwnd , &rect ) ;
      hdc = BeginPaint( hwnd , &paint ) ;
      winx = rect.right ;
      winy = rect.bottom ;

      show_al( hdc ) ;

      EndPaint( hwnd , &paint ) ;
      break ;
    case WM_DESTROY :
      PostQuitMessage( 0 ) ;       /* send a WM_QUIT to the message queue */
      break ;
    default :                      /* for messages that we don't deal with */
      return DefWindowProc (hwnd, message, wParam, lParam);
  }

  return 0 ;
}

QuestionRe: [win32] VR double buffering ? Pin
David Crow31-Oct-17 8:01
David Crow31-Oct-17 8:01 
AnswerRe: [win32] VR double buffering ? Pin
Richard MacCutchan31-Oct-17 22:40
mveRichard MacCutchan31-Oct-17 22:40 
GeneralRe: [win32] VR double buffering ? Pin
bluatigro1-Nov-17 0:37
bluatigro1-Nov-17 0:37 
GeneralRe: [win32] VR double buffering ? Pin
Richard MacCutchan1-Nov-17 1:03
mveRichard MacCutchan1-Nov-17 1:03 
SuggestionRe: [win32] VR double buffering ? Pin
David Crow1-Nov-17 3:36
David Crow1-Nov-17 3:36 
GeneralRe: [win32] VR double buffering ? Pin
bluatigro2-Nov-17 0:20
bluatigro2-Nov-17 0:20 
Questionpassing parameters to Cdialog Pin
ForNow30-Oct-17 12:11
ForNow30-Oct-17 12:11 
GeneralRe: passing parameters to Cdialog Pin
Sascha Lefèvre30-Oct-17 12:28
professionalSascha Lefèvre30-Oct-17 12:28 
GeneralRe: passing parameters to Cdialog Pin
ForNow30-Oct-17 13:13
ForNow30-Oct-17 13:13 
GeneralRe: passing parameters to Cdialog Constructer defination Pin
ForNow30-Oct-17 13:19
ForNow30-Oct-17 13:19 
QuestionRe: passing parameters to Cdialog Constructer defination Pin
David Crow31-Oct-17 2:48
David Crow31-Oct-17 2:48 
AnswerRe: passing parameters to Cdialog Constructer defination Pin
ForNow31-Oct-17 2:58
ForNow31-Oct-17 2:58 
GeneralRe: passing parameters to Cdialog Pin
Sascha Lefèvre30-Oct-17 14:03
professionalSascha Lefèvre30-Oct-17 14:03 
GeneralRe: passing parameters to Cdialog Pin
Rick York30-Oct-17 15:26
mveRick York30-Oct-17 15:26 
GeneralRe: passing parameters to Cdialog Pin
Richard MacCutchan30-Oct-17 22:45
mveRichard MacCutchan30-Oct-17 22:45 
GeneralRe: passing parameters to Cdialog Pin
Jochen Arndt30-Oct-17 23:06
professionalJochen Arndt30-Oct-17 23:06 
Questionpascals triangle using user-define function use. Not working ! Pin
Tarun Jha28-Oct-17 8:50
Tarun Jha28-Oct-17 8:50 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.