Jump to content

  • Log In with Google      Sign In   
  • Create Account

Banner advertising on our site currently available from just $5!


1. Learn about the promo. 2. Sign up for GDNet+. 3. Set up your advert!


taby

Member Since 10 Feb 2005
Offline Last Active Jun 24 2015 11:33 AM

Topics I've Started

ray tracing image plane

05 June 2015 - 12:05 PM

I'm trying to do ray tracing but I'm having no luck with the code that converts an x,y pixel into an x,y,z world position. The image plane is at z = 0, so the distance from the camera to the image plane is 1. I'm trying to avoid using glUnProject

 

My code is in void mouse_func, near the top of the snippet below:

#include <cstdlib>
#include <cmath>
#include <GLUT/glut.h>  /* Header File For The GLut Library*/
 
#include <string>
using std::string;
 
#include <sstream>
using std::ostringstream;
 
#include <iostream>
using std::cout;
using std::endl;
 
 
GLint win_id = 0;
GLint win_x = 800, win_y = 600;
 
int mouse_x = 0;
int mouse_y = 0;
bool lmb_down = false;
bool mmb_down = false;
bool rmb_down = false;
 
float last_click_float_x = 0;
float last_click_float_y = 0;
 
 
 
void mouse_func(int button, int state, int x, int y)
{
    if(GLUT_LEFT_BUTTON == button)
    {
        if(GLUT_DOWN == state)
            lmb_down = true;
        else
        {
            lmb_down = false;
            
            
            
            float aspect = static_cast<float>(win_x)/static_cast<float>(win_y);
            
            float fx = 2 * (float(x) / win_x) - 1;
            float fy = 2 * (float(y) / win_y) - 1;
            
            
            float tangent = tan(0.785398163  / 2);
            last_click_float_x = aspect * tangent * fx;
            last_click_float_y = tangent * fy;
            
            
            
            
        }
    }
    else if(GLUT_MIDDLE_BUTTON == button)
    {
        if(GLUT_DOWN == state)
            mmb_down = true;
        else
            mmb_down = false;
    }
    else if(GLUT_RIGHT_BUTTON == button)
    {
        if(GLUT_DOWN == state)
            rmb_down = true;
        else
            rmb_down = false;
    }
    
}
 
 
void draw_objects(void)
{
    glPushMatrix();
    
    
    glDisable(GL_LIGHTING);
    
    glPointSize(4.0);
    glColor3f(1, 1, 1);
 
    
    glBegin(GL_POINTS);
        glVertex3f(last_click_float_x, last_click_float_y, 0);
    glEnd();
    
    
    
 
    glPopMatrix();
}
 
 
 
 
void display_func(void)
{
    glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
    
    // Draw the model's components using OpenGL/GLUT primitives.
    draw_objects();
    
    glFlush();
    glutSwapBuffers();
}
 
 
void init_opengl(const int &width, const int &height)
{
    win_x = width;
    win_y = height;
    
    if(win_x < 1)
        win_x = 1;
    
    if(win_y < 1)
        win_y = 1;
    
    glutInitDisplayMode(GLUT_RGB|GLUT_DOUBLE|GLUT_DEPTH);
    glutInitWindowPosition(0, 0);
    glutInitWindowSize(win_x, win_y);
    win_id = glutCreateWindow("GLUT Window");
    
    glEnable(GL_DEPTH_TEST);
    glDepthFunc(GL_LEQUAL);
    glDepthMask(GL_TRUE);
    glShadeModel(GL_SMOOTH);
    glEnable(GL_CULL_FACE);
    glCullFace(GL_BACK);
    
    glClearColor(0, 0, 0, 1);
    glClearDepth(1.0f);
    
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    
    gluPerspective(45.0,
                   static_cast<GLfloat>(win_x)/static_cast<GLfloat>(win_y),
                   0.01, 20.0);
    
    gluLookAt(0,0,1, // Eye position.
              0,0,-1, // Look at position (not direction).
              0,1,0); // Up direction vector.
}
 
void reshape_func(int width, int height)
{
    win_x = width;
    win_y = height;
    
    if(win_x < 1)
        win_x = 1;
    
    if(win_y < 1)
        win_y = 1;
    
    glutSetWindow(win_id);
    glutReshapeWindow(win_x, win_y);
    glViewport(0, 0, win_x, win_y);
    
    gluPerspective(45.0,
                   static_cast<GLfloat>(win_x)/static_cast<GLfloat>(win_y),
                   0.01, 20.0);
    
    gluLookAt(0,0,1, // Eye position.
              0,0,-1, // Look at position (not direction).
              0,1,0); // Up direction vector.
    
}
 
void idle_func(void)
{
    glutPostRedisplay();
}
 
void keyboard_func(unsigned char key, int x, int y)
{
    switch(tolower(key))
    {
            
        default:
            break;
    }
}
 
 
 
void motion_func(int x, int y)
{
    int prev_mouse_x = mouse_x;
    int prev_mouse_y = mouse_y;
    
    mouse_x = x;
    mouse_y = y;
    
    int mouse_delta_x = mouse_x - prev_mouse_x;
    int mouse_delta_y = prev_mouse_y - mouse_y;
}
 
void passive_motion_func(int x, int y)
{
    mouse_x = x;
    mouse_y = y;
}
 
int main(int argc, char** argv)
{
    glutInit(&argc, argv);
    
    init_opengl(win_x, win_y);
    
    glutReshapeFunc(reshape_func);
    glutDisplayFunc(display_func);
    glutIdleFunc(idle_func);
    glutKeyboardFunc(keyboard_func);
    glutMouseFunc(mouse_func);
    glutMotionFunc(motion_func);
    glutPassiveMotionFunc(passive_motion_func);
    glutMainLoop();
 
    return 0;
}
 

X3DB format

20 April 2015 - 06:05 PM

Does anyone have any experience with the X3DB format? I'm wondering if there's any source code to demonstrate how to read and write in this format.


Shapeways and 3D printing

15 April 2015 - 10:33 AM

Hello

 

Is anyone here a designer on Shapeways? I've got some quaternion fractal designs at http://www.shapeways.com/designer/shawn_halayka

 

What isosurface algorithm do you use to make your models (ie. Marching Cubes)?


Four pillars of object oriented programming

09 May 2014 - 10:32 AM

What are the four pillars of object oriented programming, with regards to C++? I've googled and googled this subject, and there are different answers depending on which site you visit. What is your impression as to what the four pillars are? I've given my impression below, in the form of code snippets. Are these snippets the correct way to think of the four pillars?

 

Simple class / object:

#include <iostream>
using std::cout;
using std::endl;


class A
{
public:
    A(void)
    {
        value1 = 123;
    }

    int value1;
};


int main(void)
{
    A a;
    cout << a.value1 << endl;

    return 0;
}

Pillar 1 encapsulation:

#include <iostream>
using std::cout;
using std::endl;


class A
{
public:
    A(void)
    {
        value1 = 123;
    }

// Encapsulating the member variable by making it protected from code
// that exists outside of the class    
protected:
    int value1;

public:
    int getvalue1(void)
    {
        return value1;
    }

    void setvalue1(const int value)
    {
        value1 = value;
    }
};


int main(void)
{
    A a;
    cout << a.getvalue1() << endl;

    return 0;
}

Pillar 2 inheritence:

#include <iostream>

using std::cout;
using std::endl;


// Base class
class A
{
public:
    A(void)
    {
        value1 = 123;
    }

protected:
    int value1;

public:
    int getvalue1(void)
    {
        return value1;
    }

    void setvalue1(const int value)
    {
        value1 = value;
    }
};


// Inheriting class
class B: public A
{
public:
    B(void)
    {
        value2 = 456;
    }

protected:
    int value2;

public:
    int getvalue2(void)
    {
        return value2;
    }

    void setvalue2(const int value)
    {
        value2 = value;
    }
};


int main(void)
{
    B b;
    cout << b.getvalue1() << ' ' << b.getvalue2() << endl;

    return 0;
}

Pillar 3 abstraction (abstract class):

#include <iostream>
using std::cout;
using std::endl;


// Abstract base class (cannot be instantiated due to pure virtual member function)
class A
{
public:
    virtual void talk(void) = 0;
};

// Inheriting class must implement pure virtual function talk()
class B: public A 
{
public:
    void talk(void)
    {
        cout << "Class B" << endl;
    }
};


int main(void)
{
    B b;
    b.talk();

    return 0;
}

Pillar 4 polymorphism:

#include <iostream>
using std::cout;
using std::endl;


// Abstract base class (cannot be instantiated due to pure virtual member function)
class A
{
public:
    virtual void talk(void) = 0;
};

// Inheriting class must implement pure virtual function
class B: public A 
{
public:
    void talk(void)
    {
        cout << "Class B" << endl;
    }
};

// Inheriting class must implement pure virtual function
class C: public A 
{
public:
    void talk(void)
    {
        cout << "Class C" << endl;
    }
};


int main(void)
{
    B b;
    b.talk();

    C c;
    c.talk();

    // Also see general function overloading as an example of polymorphism
    // ie:
    // int add(int a, int b) { return a + b }
    // float add(float a, float b) { return a + b }
    //
    // Also see templates
    // ie:
    // STL containers

    return 0;
}

A Song of Ice and Fire -- per character chapter lists

09 January 2014 - 04:40 PM

The A Song of Ice and Fire by GRR Martin chapter data were obtained from Apple iBooks version.

 

The following per character chapter lists allow one to read a particular character's story from start to end (for instance, Arya, Jaime, etc).

The per character chapter lists were obtained from custom software (https://sites.google.com/site/asoiafchapters/asoiaf_per_character_chapter_list.zip).

The per character chapter lists contain spoilers, and aren't meant for use until after the A Song of Ice and Fire series has been read through at least once.

The per character chapter lists are in the public domain (free to use, modify and distribute).
 


==Per Character Chapter Lists==

Aeron in The Prophet:
A Feast for Crows Ch 1.

Aeron in The Drowned Man:
A Feast for Crows Ch 19.

Alayne:
A Feast for Crows Ch 23, Ch 41.

Areo in The Captain of Guards:
A Feast for Crows Ch 2.

Areo as The Watcher:
A Dance with Dragons Ch 38.

Arianne in The Queenmaker:
A Feast for Crows Ch 21.

Arianne in The Princess in the Tower:
A Feast for Crows Ch 40.

Arya:
A Game of Thrones Ch 7, Ch 22, Ch 32, Ch 50, Ch 65,
A Clash of Kings Ch 1, Ch 5, Ch 9, Ch 14, Ch 19, Ch 26, Ch 30, Ch 38, Ch 47, Ch 64,
A Storm of Swords Ch 3, Ch 13, Ch 17, Ch 22, Ch 29, Ch 34, Ch 39, Ch 43, Ch 47, Ch 50, Ch 52, Ch 65, Ch 74,
A Feast for Crows Ch 6, Ch 22.

Arya in Cat of the Canals:
A Feast for Crows Ch 34.

Arya in The Blind Girl:
A Dance with Dragons Ch 45.

Arya in The Ugly Little Girl:
A Dance with Dragons Ch 64.

Arys in The Soiled Knight:
A Feast for Crows Ch 13.

Asha in The Kraken's Daughter:
A Feast for Crows Ch 11.

Asha in The Wayward Bride:
A Dance with Dragons Ch 26.

Asha in The King's Prize:
A Dance with Dragons Ch 42.

Bran:
A Game of Thrones Ch 1, Ch 8, Ch 17, Ch 24, Ch 37, Ch 53, Ch 66,
A Clash of Kings Ch 4, Ch 16, Ch 21, Ch 28, Ch 35, Ch 46, Ch 69,
A Storm of Swords Ch 9, Ch 24, Ch 40, Ch 56,
A Dance with Dragons Ch 4, Ch 13, Ch 34.

Brienne:
A Feast for Crows Ch 4, Ch 9, Ch 14, Ch 20, Ch 25, Ch 31, Ch 37, Ch 42.

Catelyn:
A Game of Thrones Ch 2, Ch 6, Ch 14, Ch 18, Ch 28, Ch 34, Ch 40, Ch 55, Ch 59, Ch 63, Ch 71,
A Clash of Kings Ch 7, Ch 22, Ch 31, Ch 33, Ch 39, Ch 45, Ch 55,
A Storm of Swords Ch 2, Ch 14, Ch 20, Ch 35, Ch 45, Ch 49, Ch 51, Epilogue.

Cersei:
A Feast for Crows Ch 3, Ch 7, Ch 12, Ch 17, Ch 24, Ch 28, Ch 32, Ch 36, Ch 39, Ch 43,
A Dance with Dragons Ch 54, Ch 65.

Daenerys:
A Game of Thrones Ch 3, Ch 11, Ch 23, Ch 36, Ch 46, Ch 54, Ch 61, Ch 64, Ch 68, Ch 72,
A Clash of Kings Ch 12, Ch 27, Ch 40, Ch 48, Ch 63,
A Storm of Swords Ch 8, Ch 23, Ch 27, Ch 42, Ch 57, Ch 71,
A Dance with Dragons Ch 2, Ch 11, Ch 16, Ch 23, Ch 30, Ch 36, Ch 43, Ch 50, Ch 52, Ch 71.

Davos:
A Clash of Kings Ch 10, Ch 42, Ch 58,
A Storm of Swords Ch 5, Ch 10, Ch 25, Ch 36, Ch 54, Ch 63,
A Dance with Dragons Ch 9, Ch 15, Ch 19, Ch 29.

Eddard:
A Game of Thrones Ch 4, Ch 12, Ch 16, Ch 20, Ch 25, Ch 27, Ch 30, Ch 33, Ch 35, Ch 39, Ch 43, Ch 45, Ch 47, Ch 49, Ch 58.

Griff in The Lost Lord:
A Dance with Dragons Ch 24.

Jaime:
A Storm of Swords Ch 1, Ch 11, Ch 21, Ch 31, Ch 37, Ch 44, Ch 62, Ch 67, Ch 72,
A Feast for Crows Ch 8, Ch 16, Ch 27, Ch 30, Ch 33, Ch 38, Ch 44,
A Dance with Dragons Ch 48.

Jaime and Brienne combined:
A Storm of Swords Ch 1, Ch 11, Ch 21, Ch 31, Ch 37, Ch 44, Ch 62, Ch 67, Ch 72,
A Feast for Crows Ch 4, Ch 8, Ch 9, Ch 14, Ch 16, Ch 20, Ch 25, Ch 27, Ch 30, Ch 31, Ch 33, Ch 37, Ch 38, Ch 42 Ch 44,
A Dance with Dragons Ch 48.

Jon:
A Game of Thrones Ch 5, Ch 10, Ch 19, Ch 26, Ch 41, Ch 48, Ch 52, Ch 60, Ch 70,
A Clash of Kings Ch 6, Ch 13, Ch 23, Ch 34, Ch 43, Ch 51, Ch 53, Ch 68,
A Storm of Swords Ch 7, Ch 15, Ch 26, Ch 30, Ch 41, Ch 48, Ch 55, Ch 64, Ch 69, Ch 73, Ch 76, Ch 79,
A Dance with Dragons Ch 3, Ch 7, Ch 10, Ch 17, Ch 21, Ch 28, Ch 35, Ch 39, Ch 44, Ch 49, Ch 53, Ch 58, Ch 69.

Jon Connington in The Griffin Reborn:
A Dance with Dragons Ch 61.

Meanwhile, back on the Wall...:
A Feast for Crows Ch 46.

Melisandre:
A Clash of Kings Prologue,
A Dance with Dragons Ch 31.

Others:
A Game of Thrones Prologue,
A Storm of Swords Prologue,
A Dance with Dragons Prologue.

Pate:
A Feast for Crows Prologue.

Quentyn in The Merchant's Man:
A Dance with Dragons Ch 6.

Quentyn in The Windblown:
A Dance with Dragons Ch 25.

Quentyn in The Spurned Suitor:
A Dance with Dragons Ch 60.

Quentyn in The Dragontamer:
A Dance with Dragons Ch 68.

Samwell:
A Storm of Swords Ch 18, Ch 33, Ch 46, Ch 75, Ch 78,
A Feast for Crows Ch 5, Ch 15, Ch 26, Ch 35, Ch 45.

Sansa:
A Game of Thrones Ch 15, Ch 29, Ch 44, Ch 51, Ch 57, Ch 67,
A Clash of Kings Ch 2, Ch 18, Ch 32, Ch 52, Ch 57, Ch 60, Ch 62, Ch 65,
A Storm of Swords Ch 6, Ch 16, Ch 28, Ch 59, Ch 61, Ch 68, Ch 80,
A Feast for Crows Ch 10.

Barristan in The Queensguard:
A Dance with Dragons Ch 55.

Barristan in The Discarded Knight:
A Dance with Dragons Ch 59.

Barristan in The Kingbreaker:
A Dance with Dragons Ch 67.

Barristan in The Queen's Hand:
A Dance with Dragons Ch 70.

Theon:
A Clash of Kings Ch 11, Ch 24, Ch 37, Ch 50, Ch 56, Ch 66,
A Dance with Dragons Ch 51.

Theon as Reek:
A Dance with Dragons Ch 12, Ch 20, Ch 32.

Theon in The Prince of Winterfell:
A Dance with Dragons Ch 37.

Theon in The Turncloak:
A Dance with Dragons Ch 41.

Theon in A Ghost in Winterfell:
A Dance with Dragons Ch 46.

Theon in The Sacrifice:
A Dance with Dragons Ch 62.

Tyrion:
A Game of Thrones Ch 9, Ch 13, Ch 21, Ch 31, Ch 38, Ch 42, Ch 56, Ch 62, Ch 69,
A Clash of Kings Ch 3, Ch 8, Ch 15, Ch 17, Ch 20, Ch 25, Ch 29, Ch 36, Ch 41, Ch 44, Ch 49, Ch 54, Ch 59, Ch 61, Ch 67,
A Storm of Swords Ch 4, Ch 12, Ch 19, Ch 32, Ch 38, Ch 53, Ch 58, Ch 60, Ch 66, Ch 70, Ch 77,
A Dance with Dragons Ch 1, Ch 5, Ch 8, Ch 14, Ch 18, Ch 22, Ch 27, Ch 33, Ch 40, Ch 47, Ch 57, Ch 66.

Varys:
A Dance with Dragons Epilogue.

Victarion:
A Dance with Dragons Ch 63.

Victarion in The Iron Captain:
A Feast for Crows Ch 18.

Victarion in The Reaver:
A Feast for Crows Ch 29.

Victarion in The Iron Suitor:
A Dance with Dragons Ch 56.


PARTNERS