raytracer
-
some stupid mistakes removed
// bluatigro 1 okt 2017
// windows raytracer 0.1#include
#includeconst 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
You do realize that on Windows the whole GetPixel thing is pointless you can pull the whole screen in one call to whatever colour depth and specification you want. GetDIBits function (Windows)[^] They even provide the sample Capturing an Image (Windows)[^]
In vino veritas
-
You do realize that on Windows the whole GetPixel thing is pointless you can pull the whole screen in one call to whatever colour depth and specification you want. GetDIBits function (Windows)[^] They even provide the sample Capturing an Image (Windows)[^]
In vino veritas
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
#includeconst 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 ; -
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
#includeconst 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 ;So many typing errors .. use of ( ) instead of [ ], spelling errors, incorrect types. You had a mixture of unicode and ascii text so I added #include and put all the text in _T( ) macro so they work either way. I also assume you realize you haven't started the D3D render system so your D3d stuff wont work you will just get black screen. Fixed to at least compile. I assume you sent in the wrong window handle because it does a magnificent full screen capture (that is window handle was zero) rather than capture your actual program window so you get a nice bitmap of your entire screen :-)
// bluatigro 1 okt 2017
// windows raytracer 0.2#include
#include
#include
#includeconst 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, 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);
}struct Matrial
{
d3d diffuse;
double reflection;
};
Matrial material;//const double INFINITY = 1e300; Already defined
#define SMALL 1e-300
#define PI 3.141592658class 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(t -
So many typing errors .. use of ( ) instead of [ ], spelling errors, incorrect types. You had a mixture of unicode and ascii text so I added #include and put all the text in _T( ) macro so they work either way. I also assume you realize you haven't started the D3D render system so your D3d stuff wont work you will just get black screen. Fixed to at least compile. I assume you sent in the wrong window handle because it does a magnificent full screen capture (that is window handle was zero) rather than capture your actual program window so you get a nice bitmap of your entire screen :-)
// bluatigro 1 okt 2017
// windows raytracer 0.2#include
#include
#include
#includeconst 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, 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);
}struct Matrial
{
d3d diffuse;
double reflection;
};
Matrial material;//const double INFINITY = 1e300; Already defined
#define SMALL 1e-300
#define PI 3.141592658class 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(t@ 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 ; -
@ 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 ;Still not following why you are doing software renderer you are on windows you can setup the hardware accelerated renderer. Beside that 2 other comments ... 1.) Your value of Pi is wrong 1000 places of Pi[^] 2.) You obviously struggling to make frame filename and frame is already use .. try this
void frameName (TCHAR* buffer, int bufsize, const TCHAR* nameStart, const TCHAR* ext, int no, int len)
{
// format string must be ascii .. do not change these 2 lines even on unicode
// I know its strange but thats the way it is .. format strings are always ascii
char fmtstring[32];
sprintf_s(fmtstring, _countof(fmtstring), "%s%i%s", "%s%0", len, "i.%s");
// Okay now we swing unicode/ascii for actual string
_stprintf_s(buffer, bufsize, fmtstring, nameStart, no, ext);
}It looks slightly strange because you have to make the format string. "%s%08i.%s" is an example format string, which basically says string + integer to 8 digits + . + string The problem is you don't want a constant 8 you want Len so you have to 1st build the format string Example of use of what I suspect you are trying to do. Len I assume is length of number padded with "0"'s
TCHAR buf\[256\]; frameName(buf, \_countof(buf), \_T("test"), \_T("bmp"), 1, 6); // Will give Test000001.bmp in buf
If you haven't run across TCHAR before it is a character type that changes with compile mode. In Ansi mode it is char In unicode mode it is wchar I have no idea if you are compiling in ansi mode or unicode, you had both so I am trying to be careful to support either which is what using TCHAR does. However you need to be aware TCHAR size changes. That is the reason for using _countof() rather than sizeof() for the buffer size.
In vino veritas
-
@ 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 ;I assume this is what you are trying to do GitHub - LdB-ECM/Tiny-Renderer: Software Renderer[^] I just doctored Dmitry V. Sokolov's great software renderer.
In vino veritas
-
I assume this is what you are trying to do GitHub - LdB-ECM/Tiny-Renderer: Software Renderer[^] I just doctored Dmitry V. Sokolov's great software renderer.
In vino veritas
@ 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 ?
-
@ 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 ?
hardware raytracing ?
do you meen openGL ?
or directx ?Those or any of the other hardware renderer frameworks?
in vs2017 i cant do c++
yes you can on the VS2017 app folder run the installer again and tick the box. It doesn't install by default you have to select it, think only C# gets setup by default :-) Select it as shown on this image https://github.com/LdB-ECM/Docs_and_Images/blob/master/Images/VS2017.jpg?raw=true
in vb2017 i cant do opengl or directx
Again yes you can you just have to manual handle the API calls ... is it easy, well no :-) Walkthrough: Calling Windows APIs (Visual Basic) | Microsoft Docs[^]
this is also a try at better c++ understanding
That I agree with and you have obviously made progress in that area.
I can't run c++ on my work pc, is there a c++ ide you can start [ and compiles ] from usb ?
You can install VS2017 onto a USB drive you just need to make sure the drive is mapped to a known letter. I actually do that my VS2017 is on an external harddrive that I map to G: I just make sure on any machine I wish to use the compiler I set the USB driver letter to G:. It's slows slightly on USB2 but on USB3 drive and port you can't notice the difference.
In vino veritas
-
hardware raytracing ?
do you meen openGL ?
or directx ?Those or any of the other hardware renderer frameworks?
in vs2017 i cant do c++
yes you can on the VS2017 app folder run the installer again and tick the box. It doesn't install by default you have to select it, think only C# gets setup by default :-) Select it as shown on this image https://github.com/LdB-ECM/Docs_and_Images/blob/master/Images/VS2017.jpg?raw=true
in vb2017 i cant do opengl or directx
Again yes you can you just have to manual handle the API calls ... is it easy, well no :-) Walkthrough: Calling Windows APIs (Visual Basic) | Microsoft Docs[^]
this is also a try at better c++ understanding
That I agree with and you have obviously made progress in that area.
I can't run c++ on my work pc, is there a c++ ide you can start [ and compiles ] from usb ?
You can install VS2017 onto a USB drive you just need to make sure the drive is mapped to a known letter. I actually do that my VS2017 is on an external harddrive that I map to G: I just make sure on any machine I wish to use the compiler I set the USB driver letter to G:. It's slows slightly on USB2 but on USB3 drive and port you can't notice the difference.
In vino veritas
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
#includeconst 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
{ -
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
#includeconst 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
{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
#includeconst 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