/*
* =====================================================================================
*
* Filename: sample.cpp
*
* Description: Sample viewer of procedurally generated texture
*
* Version: 1.0
* Created: 11/08/2011 20:49:55
* Revision: none
* Compiler: gcc
*
* Author: John Ryland (jryland), jryland@xiaofrog.com
* Company: InvertedLogic
*
* =====================================================================================
*/
#include <QPainter>
#include <sample.h>
#include <noise.h>
Sample::Sample(const char *file) : QGLWidget()
{
initNormalTable();
buildNormalTable();
}
Sample::~Sample()
{
}
//void Sample::paintEvent(QPaintEvent *pe)
void Sample::paintGL()
{
//QPainter p(this);
// Set background colour and clear
glClearColor(1.0, 1.0, 1.0, 1.0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);
glLineWidth(1.0);
glPointSize(1.0);
glEnable(GL_POINT_SMOOTH);
glEnable(GL_CULL_FACE);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(90, 1.0f, 0.01f, 100000.0f);
glMatrixMode(GL_MODELVIEW);
for (int i = 0; i < (1<<16); i++)
{
vec3 v = normalTable[i];
Normalize(v);
if ( v.x || v.y || v.z )
{
glBegin(GL_LINES);
v.x = v.x * 100.0;
v.y = v.y * 100.0;
v.z = v.z * 100.0;
vec3 v2( v.x*0.8, v.y*0.8, v.z*0.8);
v.z = v.z + 40.0;
v2.z = v2.z + 40.0;
GLfloat v1[3], v3[3];
v1[0] = v.x;
v1[1] = v.y;
v1[2] = v.z;
v3[0] = v2.x;
v3[1] = v2.y;
v3[2] = v2.z;
glVertex3fv((GLfloat*) v1 );// (*ie)->vertices[0]->floatData() );
glVertex3fv((GLfloat*) v3 );//(*ie)->vertices[1]->floatData() );
glEnd();
}
}
/*
//for (int i = 0; i < (1<<16); i++)
for (int i = 0; i < (1<<16); i++)
{
vec3 v = normalTable[i];
Normalize(v);
if ( v.x || v.y || v.z )
{
vec3 v2( v.x*0.98, v.y*0.98, v.z*0.98);
v.z = v.z + 4.0;
v.x = v.x + 2.0;
v2.z = v2.z + 4.0;
v2.x = v2.x + 2.0;
int x1 = 450.0 * v.x / (v.z);
int y1 = 450.0 * v.y / (v.z);
int x2 = 450.0 * v2.x / (v2.z);
int y2 = 450.0 * v2.y / (v2.z);
p.drawLine(200 + x1, 200 + y1, x2 + 200, y2 + 200);
}
}
*/
}