Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
B

bluatigro

@bluatigro
About
Posts
29
Topics
10
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • Quantum Computing sim ?
    B bluatigro

    this is what i understand of does it look right / match what the site gives ? if error's : where / what else i have NO experiance whit a QC how to use my c++ stuf whit a example from the ibm site ?

    C / C++ / MFC csharp c++ question

  • Quantum Computing sim ?
    B bluatigro

    this is verry interesting :

    Quote:

    https://quantumexperience.ng.bluemix.net/qx/experience

    i tryed to get it in c++ its a start i been programming clasical computers for +-30 year's i not even shure i wil understad this [ if ever ]

    // bluatigro 8 nov 2017
    // QC sim
    // see :
    // https://quantumexperience.ng.bluemix.net/qx/experience

    #include #include #include void rot( double & k , double & l , double r)
    {
    double s , c , hk , hl ;
    s = sin( r ) ;
    c = cos( r ) ;
    hk = k * c - l * s ;
    hl = k * s + l * c ;
    k = hk ;
    l = hl ;
    }
    const double PI = atn( 1.0 ) * 4.0 ;

    class Qbit
    {
    public :
    double x , y , z ;
    Qbit() // |0>
    {
    x = 0.0 ;
    y = 0.0 ;
    z = 1.0 ;
    }
    Qbit( double a , double b , double c )
    {
    x = a ;
    y = b ;
    z = c ;
    }
    void X()
    {
    rot( y , z , PI ) ;
    }
    void Y()
    {
    rot( x , z , PI ) ;
    }
    void Z()
    {
    rot( x , y , PI ) ;
    }
    void H() // |+>
    {
    ;
    }
    void S()
    {
    rot( x , y , PI / 2 ) ;
    }
    void S1()
    {
    rot( x , y , -PI / 2 ) ;
    }
    void T()
    {
    rot( x , y , PI / 4 ) ;
    }
    void T1()
    {
    rot( x , y , -PI / 4 ) ;
    }
    double get_state()
    {
    return z < 0.0 ? 1.0 : 0.0 ;
    }
    } ;
    void cnot( Qbit & control , Qbit & target )
    {
    if ( control.get_state() == 1.0 )
    target.z = 1.0 - target.z ;
    }

    using namespace std ;

    int main()
    {
    cout << "Hello world!" << endl;
    return 0;
    }

    C / C++ / MFC csharp c++ question

  • [win32] sprite error ?
    B bluatigro

    by me pc its giving error's if i knew what to do i won't ask this is new to me what do i ad / change so it does work as expected ? it shoot show a sprite 'player.bmp' whit cursor control

    C / C++ / MFC graphics help question

  • [win32] sprite error ?
    B bluatigro

    ok done that how do i proseed next ?

    case WM\_PAINT :
      hdc = BeginPaint( hwnd , &paint ) ;
      GetClientRect( hwnd , &rect ) ;
      winx = rect.right ;
      winy = rect.bottom ;
    
      player.bmphdc = CreateCompatibleDC( hdc ) ;
    
      player.show( hdc ) ;
    
      DeleteDC( player.bmphdc ) ;
    
      EndPaint( hwnd , &paint ) ;
      break ;
    case WM\_DESTROY :
    
    C / C++ / MFC graphics help question

  • [win32] sprite error ?
    B bluatigro

    ok i try it i changed the folowing : player.loadbmpformfil( ,_T("player.bmp)) ; my sprite looks like this now :

    class Sprite
    {
    public :
    int x , y , w , h ;
    bool visable ;
    HBITMAP hbmp ;
    HDC bmphdc ;
    Sprite(){;}
    void loadbmpfromfile( HINSTANCE hinstance , TCHAR * file )
    {
    hbmp = LoadBitmap( hinstance , file ) ;
    w = hbmp.i ;
    h = hbmp.i ;
    visable = true ;
    }
    void show( HDC hdc )
    {
    if ( visable )
    {
    //draw mask whit and [ upper half of bmp ]
    BitBlt( hdc , x , y , w , h/2 , bmphdc , 0 , 0 , MERGECOPY ) ;
    //draw picture whit or [ lower half of bmp ]
    BitBlt( hdc , x , y , w , h/2 , bmphdc , 0 , h/2 , MERGEPAINT ) ;
    }
    }
    bool hit( Sprite spr )
    {
    if ( x + w < spr.x ) return false ;
    if ( x > spr.x + spr.w ) return false ;
    if ( y + h < spr.y ) return false ;
    if ( y > spr.y + spr.h ) return false ;
    return true ;
    }
    } ;
    Sprite player ;

    i know this is wrong . how do i do this ? my wm_paint :

    case WM\_PAINT :
      GetClientRect( hwnd , &rect ) ;
      winx = rect.right ;
      winy = rect.bottom ;
    
      player.bmphdc = CreateCompatibleDC(hdc);
    
      player.show( hdc ) ;
    
      DeleteDC( player.bmphdc ) ;
    
      EndPaint( hwnd , &paint ) ;
    

    this can be wrong . how do i do this ?

    C / C++ / MFC graphics help question

  • [win32] VR double buffering ?
    B bluatigro

    i use the mdsn site + goolge for info yes its a lot of code i wrote it myself and i don't expect the error's to be fount fast the problem whit my code is that you see the drawing of the triangles over eatch other i think i have to change somthing in WM_PAINT but i m not sure

    C / C++ / MFC help question

  • [win32] sprite error ?
    B bluatigro

    a error font by the compler can have a source elsewere so i have to post al the code i don't know how to include the line numbers my english in writing is not great so i have to be short

    C / C++ / MFC graphics help question

  • [win32] sprite error ?
    B bluatigro

    error : 24 no operator = for thie 104 string to TCHAR warning i have a 'player.bmp' in the same map

    // blua tigro 1 nov 2017
    // sprite 1

    #if defined(UNICODE) && !defined(_UNICODE)
    #define _UNICODE
    #elif defined(_UNICODE) && !defined(UNICODE)
    #define UNICODE
    #endif

    #include
    #include
    bool key[ 256 ] ;
    int winx , winy ;
    #define FRAME_TIMER 1
    class Sprite
    {
    public :
    int x , y , w , h ;
    bool visable ;
    BITMAP bmp ;
    Sprite(){;}
    void loadbmpfromfile( HINSTANCE hinstance , TCHAR * file )
    {
    bmp = LoadBitmap( hinstance , _T( file ) ) ;
    w = bmp.bmWidth ;
    h = bmp.bmHeight ;
    visable = true ;
    }
    void show( HDC hdc )
    {
    if ( visable )
    {
    //draw mask whit and [ upper half of bmp ]
    BitBlt( hdc , x , y , w , h/2 , hdc , 0 , 0 , MERGECOPY ) ;
    //draw picture whit or [ lower half of bmp ]
    BitBlt( hdc , x , y , w , h/2 , hdc , 0 , h/2 , MERGEPAINT ) ;
    }
    }
    bool hit( Sprite spr )
    {
    if ( x + w < spr.x ) return false ;
    if ( x > spr.x + spr.w ) return false ;
    if ( y + h < spr.y ) return false ;
    if ( y > spr.y + spr.h ) return false ;
    return true ;
    }
    } ;
    Sprite player ;
    /* Declare Windows procedure */
    LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);

    /* Make the class name into a global variable */

    = _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;                      /
    
    C / C++ / MFC graphics help question

  • [win32] VR double buffering ?
    B bluatigro

    the code shoot show a colored rotating cube i want to get rid of showing drawing it gives ugly effects i want double buffering i have no idea where / what i have to change in the code to that effect i got now : WS_POPUP | WS_MAXIMIZE how do i get fulscreen ?

    C / C++ / MFC help question

  • [win32] VR double buffering ?
    B bluatigro

    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
    #include
    #include
    #include
    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

    C / C++ / MFC help question

  • [ win32 ][ code::block's ] game 1 error ?
    B bluatigro

    update : i tryed it [ thanks for sugestions and i got somthing on screen error : my screen isn't black and isn't fulscreen my ellipse isn't yellow

    // bluatigro 23 okt 2017
    // win game 1

    #if defined(UNICODE) && !defined(_UNICODE)
    #define _UNICODE
    #elif defined(_UNICODE) && !defined(UNICODE)
    #define UNICODE
    #endif

    #include
    #include

    bool key[ 256 ] ;
    int playerx , playery , winx , winy ;
    #define FRAME_TIMER 1

    /* Declare Windows procedure */
    LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);

    /* Make the class name into a global variable */

    = _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)BLACK\_BRUSH;
    
    /\* 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("Game 1"),       /\* Title Text \*/
           WS\_OVERLAPPEDWINDOW | WS\_MAXIMIZE , /\* default window \*/
           CW\_USEDEFAULT,       /\* Windows decides the position \*/
           CW\_USEDEFAULT,       /\* where the window ends up on the screen
    
    C / C++ / MFC help game-dev question

  • [ win32 ][ code::block's ] game 1 error ?
    B bluatigro

    hello this is a try at a verry simple game it is a try at moving a circle whit cursor-key's i use code::block's 4 error's were detected : somting wrong whit case any help is welkome

    // bluatigro 23 okt 2017
    // win game 1

    #if defined(UNICODE) && !defined(_UNICODE)
    #define _UNICODE
    #elif defined(_UNICODE) && !defined(UNICODE)
    #define UNICODE
    #endif

    #include #include bool key[ 256 ] ;
    int playerx , playery , winx , winy ;
    #define FRAME_TIMER 1

    /* Declare Windows procedure */
    LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);

    /* Make the class name into a global variable */

    = _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("Game 1"),       /\* Title Text \*/
           WS\_OVERLAPPEDWINDOW | WS\_MAXIMIZE , /\* default window \*/
           CW\_USEDEFAULT,       /\* Windows decides the position \*/
           CW\_USEDEFAULT,
    
    C / C++ / MFC help game-dev question

  • raytracer
    B bluatigro

    update : i got most of the error's removed 2 error remains : i got a back picture on screen i can't find 'black.bmp' on my pc

    // bluatigro 23 okt 2017
    // windows raytracer 0.4

    #include
    #include
    #include
    #include

    const int winx = 800 ;
    const int winy = 600 ;

    #define SMALL 1e-300
    #define PI 3.14159265358979323846

    // double3d
    class d3d
    {
    public :
    double x , y , z ;
    d3d()
    {
    x = 0.0 ;
    y = 0.0 ;
    z = 0.0 ;
    }
    d3d( double X , double Y , double Z )
    {
    x = X ;
    y = Y ;
    z = Z ;
    }
    void fill( double X , double Y , double Z )
    {
    x = X ;
    y = Y ;
    z = Z ;
    }
    unsigned long toColor()
    {
    return (unsigned long)
    ( floor( x * 255 ) +
    floor( y * 255 ) * 256 +
    floor( z * 255 ) * 256 * 256 ) ;
    }
    } ;
    d3d operator + ( d3d a , d3d b )
    {
    return d3d( a.x + b.x ,
    a.y + b.y ,
    a.z + b.z ) ;
    }
    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 operator * ( d3d a , double b )
    {
    return d3d( a.x * b ,
    a.y * b ,
    a.z * b ) ;
    }
    double dot( d3d a , d3d b )
    {
    return a.x * b.x
    + a.y * b.y
    + a.z * b.z ;
    }
    double length( d3d a )
    {
    return sqrt( dot( a , a ) ) ;
    }
    d3d normalize( d3d a )
    {
    return a / length( a ) ;
    }
    double getAngle( d3d a , d3d b )
    {
    double d , la , lb ;
    d = dot( a , b ) ;
    la = length( a ) ;
    lb = length( b ) ;
    return acos( d / ( la * lb ) ) ;
    }
    d3d cross( d3d a , d3d b )
    {
    return d3d( a.y * b.z - a.z * b.y ,
    a.z * b.x - a.x * b.z ,
    a.x * b.y - a.y * b.x ) ;
    }
    // primary colors
    const d3d BLACK = d3d( 0.0 , 0.0 , 0.0 ) ;
    const d3d RED = d3d( 1.0 , 0.0 , 0.0 ) ;
    const d3d GREEN = d3d( 0.0 , 1.0 , 0.0 ) ;
    const d3d YELLOW = d3d( 1.0 , 1.0 , 0.0 ) ;
    const d3d BLUE = d3d( 0.0 , 0.0 , 1.0 ) ;
    const d3d MAGENTA = d3d( 1.0 , 0.0 , 1.0 ) ;
    const d3d CYAN = d3d( 0.0 , 1.0 , 1.0 ) ;
    const d3d WHITE = d3d( 1.0 , 1.0 , 1.0 ) ;
    // mix colors
    const d3d GRAY = WHITE / 2.0 ;
    const d3d ORANGE = ( YELLOW + RED ) / 2.0 ;
    const d3d PINK = ( WHITE + RED ) / 2.0 ;

    // matrix
    class m44
    {
    public :
    double m[ 4 ][ 4 ] ;
    m44()
    {
    int i , j ;
    for ( i = 0 ; i < 4 ; i++ )
    {
    fo

    C / C++ / MFC announcement

  • while error ?
    B bluatigro

    this program does not halt why ?

    //les02for.cpp
    #include
    #include
    using namespace std ;
    int main()
    {
    string in = " ";
    while ( in != "" )
    {
    cout << "What is your name ? \n" ;
    cout << "[ Pres enter to end this .]\n" ;
    cin >> in ;
    cout << "Hello " << in << " .\n" ;
    }
    cout << "n\n\n\[ GAME OVER ]\n" ;
    cin.get() ;
    return 0;
    }

    C / C++ / MFC question c++ game-dev help

  • Genetic Prorgaming
    B bluatigro

    this is a try at GP in C++ whit strings GP what : from array or grafic to formula GP how : 1 : write random formula's 2 : sort formula's on error 3 : best fumula's mix to kid's 4 : some kid's are mutated 5 : if genration < max and error > whised goto 2 version 0.1.1 building function run get "list" outof formula

    bluatigro 9 okt 2017
    // genetic programing whit strings
    // version 0.1

    #include #include #include #include #include using namespace std ;

    typedef VSTR vector ;

    VSTR split( string in , char cut = ' ' )
    {
    VSTR uit ;
    size_type i = 0 ;
    size_type j = in.find( cut ) ;
    while ( j != string::npos )
    {
    uit.push_back( in.substr( i , j - i ) ) ;
    i = ++j ;
    j = in.find( cut , j ) ;
    if ( j == string::npos )
    in.push_back( in.substr( i , in.lenght() ) ) ;
    }
    return uit ;
    }

    string dbl2str( double x )
    {
    stringsream ss ;
    ss << x ;
    return ss.str() ;
    }

    double str2dbl( string x )
    {
    // how ?
    }

    class GeneProg
    {
    private :
    int numberMode ;
    VSTR genes ;
    double in[ 10 ] ;
    int inmax ;
    public :
    GeneProg()
    {
    numberMode = 0 ;
    inmax = 0 ;
    }
    string run( string prog )
    {
    int einde = prog.find( ']' ) ;
    int begin = einde ;
    while ( prog[ begin ] != '[' ) ;
    begin-- ;
    return prog.substr( begin , einde - begin ) ;
    }
    } ;

    int main()
    {
    GeneProg GP ;
    string a = "[ + 7 [ - 2 3 ] ]" ;
    string b = "[ * 9 [ / 8 6 ] ]" ;
    cout << "[ test run ]" << endl ;
    cout << "prog a = " << a << endl ;
    //gp.run shoot give "[ - 2 3 ]"
    cout << "run a = " << GP.run( a ) << endl ;
    cout << "check a = " << 7 + ( 2 - 3 ) << endl ;
    cout << "prog b = " << b << endl ;
    //gp.run shoot give "[ / 8 6 ]"
    cout << "run b = " << GP.run( b ) << endl ;
    cout << "check b = " << 9 * ( 8 / 6 ) << endl ;
    cout << "[ game over ]" << endl ;
    cin.get() ;
    }

    C / C++ / MFC c++ graphics game-dev data-structures help

  • raytracer
    B bluatigro

    update : avatar added animation added to be sure i REMed the animation and saving part for so far i understand it is right if i add : ambient , specular , shinines , phong , emission etc... to Material how do i calc the end color ?

    bluatigro 1 okt 2017
    // windows raytracer 0.3

    #include
    #include
    #include
    #include

    const int winx = 800 ;
    const int winy = 600 ;

    #define SMALL 1e-300
    #define PI = 3.14159265358979323846

    // double3d
    class d3d
    {
    public :
    double x , y , z ;
    d3d()
    {
    x = 0.0 ;
    y = 0.0 ;
    z = 0.0 ;
    }
    d3d( double X , double Y , double Z )
    {
    x = X ;
    y = Y ;
    z = Z ;
    }
    void fill( double X , double Y , double Z )
    {
    x = X ;
    y = Y ;
    z = Z ;
    }
    unsigned long toColor()
    {
    return (unsigned long)
    ( floor( x * 255 ) +
    floor( y * 255 ) * 256 +
    floor( z * 255 ) * 256 * 256 ) ;
    }
    } ;
    d3d operator + ( d3d a , d3d b )
    {
    return d3d( a.x + b.x ,
    a.y + b.y ,
    a.z + b.z ) ;
    }
    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 operator * ( d3d a , double b )
    {
    return d3d( a.x * b ,
    a.y * b ,
    a.z * b ) ;
    }
    double dot( d3d a , d3d b )
    {
    return a.x * b.x
    + a.y * b.y
    + a.z * b.z ;
    }
    double length( d3d a )
    {
    return sqrt( dot( a , a ) ) ;
    }
    d3d normalize( d3d a )
    {
    return a / length( a ) ;
    }
    double getAngle( d3d a , d3d b )
    {
    double d , la , lb ;
    d = dot( a , b ) ;
    la = length( a ) ;
    lb = length( b ) ;
    return acos( d / ( la * lb ) ) ;
    }
    d3d cross( d3d a , d3d b )
    {
    return d3d( a.y * b.z - a.z * b.y ,
    a.z * b.x - a.x * b.z ,
    a.x * b.y - a.y * b.x ) ;
    }
    // primary colors
    const d3d BLACK = d3d( 0.0 , 0.0 , 0.0 ) ;
    const d3d RED = d3d( 1.0 , 0.0 , 0.0 ) ;
    const d3d GREEN = d3d( 0.0 , 1.0 , 0.0 ) ;
    const d3d YELLOW = d3d( 1.0 , 1.0 , 0.0 ) ;
    const d3d BLUE = d3d( 0.0 , 0.0 , 1.0 ) ;
    const d3d MAGENTA = d3d( 1.0 , 0.0 , 1.0 ) ;
    const d3d CYAN = d3d( 0.0 , 1.0 , 1.0 ) ;
    const d3d WHITE = d3d( 1.0 , 1.0 , 1.0 ) ;
    // mix colors
    const d3d GRAY = WHITE / 2.0 ;
    const d3d ORANGE = ( YELLOW + RED ) / 2.0 ;
    const d3d PINK = ( WHITE + RED ) / 2.0 ;

    // matrix
    class m44
    {

    C / C++ / MFC announcement

  • raytracer
    B bluatigro

    @ leon : hardware raytracing ? do you meen openGL ? or directx ? in vs2017 i cant do c++ in vb2017 i cant do opengl or directx in that case i won't get reflection and refraction this is also a try at better c++ understanding i can't run c++ on my work pc is there a c++ ide you can start [ and compiles ] from usb ?

    C / C++ / MFC announcement

  • raytracer
    B bluatigro

    @ leon : i m used to basic so the () inplaceof [] update : m44 class [ matrix ] added 3d engine added in the future i wil give a example of a animated avatar

    // bluatigro 1 okt 2017
    // windows raytracer 0.2

    #include #include #include #include const int winx = 800 ;
    const int winy = 600 ;

    #define SMALL 1e-300
    #define PI = 3.1415929203

    // double3d
    class d3d
    {
    public :
    double x , y , z ;
    d3d()
    {
    x = 0.0 ;
    y = 0.0 ;
    z = 0.0 ;
    }
    d3d( double X , double Y , double Z )
    {
    x = X ;
    y = Y ;
    z = Z ;
    }
    void fill( double X , double Y , double Z )
    {
    x = X ;
    y = Y ;
    z = Z ;
    }
    unsigned long toColor()
    {
    return (unsigned long)
    ( floor( x * 255 ) +
    floor( y * 255 ) * 256 +
    floor( z * 255 ) * 256 * 256 ) ;
    }
    } ;
    d3d operator + ( d3d a , d3d b )
    {
    return d3d( a.x + b.x ,
    a.y + b.y ,
    a.z + b.z ) ;
    }
    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 operator * ( d3d a , double b )
    {
    return d3d( a.x * b ,
    a.y * b ,
    a.z * b ) ;
    }
    double dot( d3d a , d3d b )
    {
    return a.x * b.x
    + a.y * b.y
    + a.z * b.z ;
    }
    double length( d3d a )
    {
    return sqrt( dot( a , a ) ) ;
    }
    d3d normalize( d3d a )
    {
    return a / length( a ) ;
    }
    double getAngle( d3d a , d3d b )
    {
    double d , la , lb ;
    d = dot( a , b ) ;
    la = length( a ) ;
    lb = length( b ) ;
    return acos( d / ( la * lb ) ) ;
    }
    d3d cross( d3d a , d3d b )
    {
    return d3d( a.y * b.z - a.z * b.y ,
    a.z * b.x - a.x * b.z ,
    a.x * b.y - a.y * b.x ) ;
    }
    // primary colors
    const d3d BLACK = d3d( 0.0 , 0.0 , 0.0 ) ;
    const d3d RED = d3d( 1.0 , 0.0 , 0.0 ) ;
    const d3d GREEN = d3d( 0.0 , 1.0 , 0.0 ) ;
    const d3d YELLOW = d3d( 1.0 , 1.0 , 0.0 ) ;
    const d3d BLUE = d3d( 0.0 , 0.0 , 1.0 ) ;
    const d3d MAGENTA = d3d( 1.0 , 0.0 , 1.0 ) ;
    const d3d CYAN = d3d( 0.0 , 1.0 , 1.0 ) ;
    const d3d WHITE = d3d( 1.0 , 1.0 , 1.0 ) ;
    // mix colors
    const d3d GRAY = WHITE / 2.0 ;
    const d3d ORANGE = ( YELLOW + RED ) / 2.0 ;
    const d3d PINK = ( WHITE + RED ) / 2.0 ;

    // matrix
    class m44
    {
    public :
    double m[ 4 ][ 4 ] ;
    m44()
    {
    int i , j ;
    for ( i = 0 ;

    C / C++ / MFC announcement

  • raytracer
    B bluatigro

    update : build leon sugestion into code : error : lots of error's [ i can't read the error-mesages due to a eye problem ]

    // bluatigro 1 okt 2017
    // windows raytracer 0.2

    #include
    #include
    #include

    const int winx = 800 ;
    const int winy = 600 ;

    typedef struct PIXEL {
    char r , g , b , a ;
    } ;

    class d3d
    {
    public :
    double x , y , z ;
    d3d()
    {
    x = 0.0 ;
    y = 0.0 ;
    z = 0.0 ;
    }
    d3d( double X , double Y , double Z )
    {
    x = X ;
    y = Y ;
    z = Z ;
    }
    void fill( double X , double Y , double Z )
    {
    x = X ;
    y = Y ;
    z = Z ;
    }
    unsigned long toColor()
    {
    return (unsigned long)
    ( floor( x * 255 ) +
    floor( y * 255 ) * 256 +
    floor( z * 255 ) * 256 * 256 ) ;
    }
    } ;
    d3d operator + ( d3d a , d3d b )
    {
    return d3d( a.x + b.x ,
    a.y + b.y ,
    a.z + b.z ) ;
    }
    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 operator * ( d3d a , d3d b )
    {
    return d3d( a.x * b ,
    a.y * b ,
    a.z * b ) ;
    }
    double dot( d3d a , d3d b )
    {
    return a.x * b.x
    + a.y * b.y
    + a.z * b.z ;
    }
    double length( d3d a )
    {
    return sqrt( dot( a , a ) ) ;
    }
    d3d normalize( d3d a )
    {
    return a / length( a ) ;
    }
    double getAngle( d3d a , d3d b )
    {
    double d , la , lb ;
    d = dot( a , b ) ;
    la = length( a ) ;
    lb = length( b ) ;
    return acos( d / ( la * lb ) ) ;
    }
    d3d cross( d3d a , d3d b )
    {
    return d3d( a.y * b.z - a.z * b.y ,
    a.z * b.x - a.x * b.z ,
    a.x * b.y - a.y * b.x ) ;
    }

    struct Matrial
    {
    d3d diffuse ;
    double reflection ;
    } ;
    Matrial matrial ;

    const double INFINITY = 1e300 ;
    const double SMALL = 1e-300 ;

    class Sphere
    {
    public :
    d3d center ;
    double radius , radius2 ;
    Matrial mat ;
    void fill( d3d c , double r )
    {
    center = c ;
    radius = r ;
    radius2 = r * r ;
    mat = material ;
    }
    double hit( d3d o , d3d d )
    {
      double t , a , b , c , disc ;
      d3d temp = o - center ;
      a = dot( d , d ) ;
      b = 2 * dot( temp , d ) ;
      c = dot( temp , temp ) - radius2 ;
      disc = b * b - 4 * a * c ;
      if ( disc < 0 )
        return INFINITY ;
      else
    {
        double e = sqrt( disc ) ;
        double demon = 2 * a ;
        t = ( -b - e ) / demon ;
        if ( t > SMALL ) return t ;
        t = ( -b + e ) / demon ;

    C / C++ / MFC announcement

  • raytracer
    B bluatigro

    some stupid mistakes removed

    // bluatigro 1 okt 2017
    // windows raytracer 0.1

    #include
    #include

    const int winx = 800 ;
    const int winy = 600 ;

    typedef struct PIXEL {
    char r , g , b , a ;
    } ;

    void saveBMP( string filename , PIXEL[][] pixel
    , int w , int h )
    {
    unsigned nWidthBytes = ((w * 24 + 31) & ~31) / 8;
    // EDIT: Corrected
    //unsigned nExtra = 8 * ((screenx * 24) % 32);
    unsigned nExtra = nWidthBytes - 3 * w ;
    unsigned nPixelSize = nWidthBytes * h ;
    BITMAPFILEHEADER FileHdr ;
    // File header
    FileHdr.bfType = 0x4D42; // "BM"
    FileHdr.bfSize = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER) + 3 * sizeof(DWORD) + nPixelSize;
    FileHdr.bfReserved1 = pBmHdr.bfReserved2 = 0;
    // EDIT: Corrected
    //FileHdr.bfOffBits = sizeof(BITMAPFILEHEADER);
    FileHdr.bfOffBits = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER) + 3 * sizeof(DWORD);
    BITMAPINFOHEADER InfoHdr ;
    // Info header for 24-bit RGB
    InfoHdr.biSize = sizeof(BITMAPINFOHEADER);
    InfoHdr.biWidth = screenx;
    InfoHdr.biHeight = screeny;
    InfoHdr.biPlanes = 1;
    InfoHdr.biBitCount = 24;
    InfoHdr.biCompression = BI_BITFIELDS;
    InfoHdr.biSizeImage = nPixelSize;
    InfoHdr.biXPelsPerMeter = 0;
    InfoHdr.biYPelsPerMeter = 0;
    InfoHdr.biClrUsed = 0;
    InfoHdr.biClrImportant = 0;
     
    // Color table (bit masks for the three colours) with BI_BITFIELDS
    // NOTE: I'm actually not sure if these must be reversed!
    DWORD clrTable[3] = { 0xff, 0xff00, 0xff0000 };
     
    fwrite(&FileHdr, 1, sizeof(BITMATFILEHEADER), file);
    fwrite(&InfoHdr, 1, sizeof(BITMATINFOHEADER), file);
    fwrite(clrTable, 1, sizeof(clrTable), file);
    for (int y = 0 ; y < ; h ; y++ )
    {
    // EDIT: Corrected
    //fwrite(pixel[y], 3, nWidthBytes, file);
    fwrite( pixel[y] , 3 , w , file ) ;
    if ( nExtra )
    {
    DWORD dummy = 0;
    fwrite( &dummy , 1 , nExtra , file ) ;
    }
    }
    }

    /* This is where all the input to the window goes to */
    LRESULT CALLBACK WndProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam) {

    HDC hdc ;
    PAINTSTRUCKT ps ;

    switch( Message ) 
    {
    	
    	case WM\_PAINT :
    		int x , y ;
    		PIXEL pixel\[ winx \]\[ winy \] ;
    		unsigned long color ; 
    		hdc = BeginPaint( hwnd , & ps ) ;
      for ( x = 0 ; x < winx ; x++ )
      {
      	for ( y = 0 ; y < winy ; y++ )
      	{
    			  if ( x > 100 && x < winx - 100
    			  && y > 100 && y < winy - 100 )
      	    color = 0xff007fff ; //orange
      	  else
      	    color = 0xff000000 ; //black
      	  pixel\[y\]\[x\].r = color & 255 ;
      	  p
    
    C / C++ / MFC announcement
  • Login

  • Don't have an account? Register

  • Login or register to search.
  • First post
    Last post
0
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups