Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Pipo DeClown

Ray Tracing Up-side-down

This topic is 5229 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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..

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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..

Share this post


Link to post
Share on other sites
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..

Share this post


Link to post
Share on other sites
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..

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!