Ray Tracing Up-side-down

Started by
14 comments, last by Pipo DeClown 20 years ago
http://www.2tothex.com/raytracing/basic.html I''ve been searching and searching for 1,5 hours now. I can''t seem to find any not differing points in my sourcecode and his. But still, the pixels are up-side-down. It is nothing with my rendering system, since other rendering is fine. When I flip the y (in my ray-directions), it works like it should. Has anyone experienced this, and knows the answer? -- You''re Welcome, Rick Wong - sitting in his chair doing the most time-consuming thing..
Advertisement
Are you by any chance using glDrawPixels to display your image? By default it displays the image data upside down, I''m not sure if this can be changed.
Hmm.. I''m using SDL.

    for(int y = 0; y < height; y++ )    {        for(int x = 0; x < width; x++ )        {            vDir = directionTable[x+y*width];                        Raytrace( vStart, vDir, screen, color );                                    Uint8 *p = (Uint8 *)screen->pixels + y * screen->pitch + x * bpp;            *(Uint16 *)p = color;        }      }


--
You''re Welcome,
Rick Wong
- sitting in his chair doing the most time-consuming thing..
That looks right to me. What is the value directionTable[0] ?
cVector* GenerateDirectionTable( int width, int height ){	cVector *direction = new cVector[width*height];	for(int y=0; y<height; y++)	{		for(int x=0; x<width; x++)		{			cVector &currDirection = direction[x+y*width];			currDirection.mX = x - width/2;			currDirection.mY = y - height/2; // if I negate this, it works			currDirection.mZ = 256;			currDirection.Normalize();		}	}	return direction;}


--
You''re Welcome,
Rick Wong
- sitting in his chair doing the most time-consuming thing..
I can provide more code, here is my cVector class:

#include "cVector.h"/*		Reading from class*/cVector cVector::operator+ ( cVector Vec ) const{	cVector tVec( mX + Vec.mX, 				  mY + Vec.mY, 				  mZ + Vec.mZ ); 	return tVec;}cVector cVector::operator- ( cVector Vec ) const{	cVector tVec( mX - Vec.mX, 				  mY - Vec.mY, 				  mZ - Vec.mZ );	return tVec;}cVector cVector::operator* ( cVector Vec ) const{	cVector tVec( mX * Vec.mX, 				  mY * Vec.mY, 				  mZ * Vec.mZ );	return tVec;}cVector cVector::operator/ ( cVector Vec ) const{	cVector tVec( mX / Vec.mX, 				  mY / Vec.mY, 				  mZ / Vec.mZ );	return tVec;}cVector cVector::operator- () const{	cVector tVec( -mX, 				  -mY, 				  -mZ );	return tVec;}/*		Writing to class*/cVector cVector::operator= ( cVector Vec ){	cVector tVec( (mX = Vec.mX), 				  (mY = Vec.mY), 				  (mZ = Vec.mZ) );	return tVec;}cVector cVector::operator+= ( cVector Vec ){	cVector tVec( (mX += Vec.mX), 				  (mY += Vec.mY), 				  (mZ += Vec.mZ) );	return tVec;}cVector cVector::operator-= ( cVector Vec ){	cVector tVec( (mX -= Vec.mX), 				  (mY -= Vec.mY), 				  (mZ -= Vec.mZ) );	return tVec;}cVector cVector::operator*= ( cVector Vec ){	cVector tVec( (mX *= Vec.mX), 				  (mY *= Vec.mY), 				  (mZ *= Vec.mZ) );	return tVec;}cVector cVector::operator/= ( cVector Vec ){	cVector tVec( (mX /= Vec.mX), 				  (mY /= Vec.mY), 				  (mZ /= Vec.mZ) );	return tVec;}/*		Comparing to class (Read only too)*/bool cVector::operator== ( cVector Vec ) const{	if( mX == Vec.mX )		if( mY == Vec.mY )			if( mZ == Vec.mZ )				return true;	return false;}bool cVector::operator!= ( cVector Vec ) const{	if( mX == Vec.mX )		if( mY == Vec.mY )			if( mZ == Vec.mZ )				return false;   // NOTE: false if everything is equal	return true;                // NOTE: true if something is not equal}bool cVector::operator>  (cVector Vec ) const{	if( mX > Vec.mX )		if( mY > Vec.mY )			if( mZ > Vec.mZ )				return true;	return false;}bool cVector::operator>= (cVector Vec ) const{	if( mX >= Vec.mX )		if( mY >= Vec.mY )			if( mZ >= Vec.mZ )				return true;	return false;}bool cVector::operator<  (cVector Vec ) const{	if( mX < Vec.mX )		if( mY < Vec.mY )			if( mZ < Vec.mZ )				return true;	return false;}bool cVector::operator<= (cVector Vec ) const{	if( mX <= Vec.mX )		if( mY <= Vec.mY )			if( mZ <= Vec.mZ )				return true;	return false;}/*    Maths and Physics*/float cVector::DotProduct( cVector Vec ) const{        return (mX*Vec.mX) + (mY*Vec.mY) + (mZ*Vec.mZ);}float cVector::CrossProduct( cVector Vec ) const{        return ( (mY*Vec.mZ - mZ*Vec.mY) +              (mZ*Vec.mX - mX*Vec.mZ) +              (mX*Vec.mY - mY*Vec.mX) );}float cVector::Magnitude() const{        return (float)sqrt((mX*mX) + (mY*mY) + (mZ*mZ));}cVector cVector::Normalize(){        float M = this->Magnitude();    if(M == 0.0f) M = 1.0f;        mX = mX / M;    mY = mY / M;    mZ = mZ / M;        return *this;}


I REALLY REALLY need this solved, been looking more than 6 hours..

--
You''re Welcome,
Rick Wong
- sitting in his chair doing the most time-consuming thing..
possibly you''re just working on a pc, while he worked on a mac, and there, the coordinates are by default, upside-down. i don''t know, but it could be :D



If that''s not the help you''re after then you''re going to have to explain the problem better than what you have. - joanusdmentia

davepermen.net
If that's not the help you're after then you're going to have to explain the problem better than what you have. - joanusdmentia

My Page davepermen.net | My Music on Bandcamp and on Soundcloud

Probably what davepermen said I don''t know if there are any endian issues between macs/pcs, but there could be.

Alternatively, you could just rotate your surface after everything''s been drawn...

My Website | Everything you need to know about 3D Graphics | Google | Search the Forums
If you use a right-handed coordinate system like in opengl, the y axis will be pointing up in world space. Then when finding the direction to send rays in you probably begin with negative and then go to positive values which mean you will end up using positive y as up-direction, and hence your image will be up side down.
i mean, on a mac, the main menu bar is on top, while on windows, the task bar is on the bottom, too..

i guess mac has 0,0 at left-top, while windows has it at left-bottom



If that''s not the help you''re after then you''re going to have to explain the problem better than what you have. - joanusdmentia

davepermen.net
If that's not the help you're after then you're going to have to explain the problem better than what you have. - joanusdmentia

My Page davepermen.net | My Music on Bandcamp and on Soundcloud

This topic is closed to new replies.

Advertisement