I have the following code
int i = 0;
void display(void)
{
glLoadIdentity();
glColor3f(1.0f, 0.0f, 0.0f);
glPushMatrix();
glTranslatef(20.0f, 20.0f, -40.f);
glRotatef(180.f, 0.0, 0.0, 1.0);
glBegin(GL_TRIANGLES);
glVertex3f(pts[tri[i]], (pts[ptsLength/2 + tri[i]] - maximum) * -1, 0);
glVertex3f(pts[tri[i+1]], (pts[ptsLength/2 + tri[i+1]] - maximum) * -1, 0);
glVertex3f(pts[tri[i+2]], (pts[ptsLength/2 + tri[i+2]] - maximum) * -1, 0);
glEnd();
i+=3;
glPopMatrix();
glutSwapBuffers();
}
How can I make this method pause and wait for a keystroke before rendering the next triangle?
Is this the glutIdleFunc, or the one called when you glutPostRedisplay?
In either case, you need to first setup a glutKeyboardFunc, in which you detect whether a certain key is pressed or not.
In the case you update the screen only on certain events:
... inside the keyboard function
if (key_pressed == THE_KEY_YOU_WANT)
glutPostRedisplay();
In the case you are using display as the idle function, you can do:
global:
bool go_next = false;
... inside the keyboard function
if (key_pressed == THE_KEY_YOU_WANT)
go_next = true;
... inside display:
void display(void)
{
if (go_next)
{
go_next = false;
glLoadIdentity();
glColor3f(1.0f, 0.0f, 0.0f);
glPushMatrix();
... etc
glPopMatrix();
}
glutSwapBuffers();
}
Side note: It is best to keep the logic and rendering separate. So perhaps a code like this is best:
int triangles_to_draw = 0;
... inside the keyboard function
if (key_pressed == THE_KEY_YOU_WANT)
process_event_next_triangle();
void process_event_next_triangle()
{
if (triangles_to_draw < maximum)
++triangles_to_draw;
}
void display(void)
{
go_next = false;
glLoadIdentity();
glColor3f(1.0f, 0.0f, 0.0f);
glPushMatrix();
glTranslatef(20.0f, 20.0f, -40.f);
glRotatef(180.f, 0.0, 0.0, 1.0);
glBegin(GL_TRIANGLES);
for (int i = 0; i < 3*triangles_to_draw; i += 3)
{
glVertex3f(pts[tri[i]], (pts[ptsLength/2 + tri[i]] - maximum) * -1, 0);
glVertex3f(pts[tri[i+1]], (pts[ptsLength/2 + tri[i+1]] - maximum) * -1, 0);
glVertex3f(pts[tri[i+2]], (pts[ptsLength/2 + tri[i+2]] - maximum) * -1, 0);
}
glEnd();
glPopMatrix();
glutSwapBuffers();
}
Note that this way, you can make the process_event_next_triangle as complicated as you want without affecting the display function. This makes life much easier when you have many keys doing different stuff.
when processing glut keyboard event add code:
if (key == DESIRED_KEY_CODE)
i+=3
and remove that i+=3 in the display() func
but note that this way we will have only one triangle at a time... if you want to show several triangles you have to have some counter of visible triangles and display them in a loop.
Related
When I execute the code I get a hot air balloon formed of three elements. My issue is that when I move the objects from the keyboard, the objects loose color, and become more like wire than solid.
From what I discovered until now, my trouble comes from this function call:
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE)
But I need it to make the ropes...
/*
This program shows a hot air balloon rotating around its own axe to the left and to the right
*/
#include "glos.h"
#include<math.h>
#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glaux.h>
void myinit(void);
void CALLBACK display(void);
void CALLBACK myReshape(GLsizei w, GLsizei h);
void CALLBACK rotateRight(void);
void CALLBACK rotateLeft(void);
static GLfloat x = 0;
static GLfloat y = 0;
static GLfloat z = 0;
static GLfloat alfa = 0;
double PI = 3.14159265;
void myinit (void) {
glClearColor(1.0, 1.0, 1.0, 1.0);
glEnable(GL_DEPTH_TEST);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glEnable(GL_COLOR_MATERIAL);
glColorMaterial(GL_FRONT_AND_BACK, GL_DIFFUSE);
}
void CALLBACK rotateLeft(void) { y -= 5; }
void CALLBACK rotateRight(void) { y += 5; }
void CALLBACK display (void)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glRotatef(x, 1, 0, 0);
glRotatef(y, 0, 1, 0);
glTranslatef(0, -80, 0);
//cube = basket
glColor3f(1, 1, 0);
auxSolidCube(50);
//full sphere = baloon
glPushMatrix();
glColor3f(1.0, 0.0, 0.0);
glTranslatef(0,200,0);
glRotatef(-90, 1, 0, 0);
auxSolidSphere(130.0);
glPopMatrix();
//polygon cylinder = ropes
glPushMatrix();
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
glBegin(GL_QUAD_STRIP);
glColor3f(0.0, 1.0, 1.0);
for (alfa = 0; alfa <= 360; alfa+=30) {
glVertex3f(65 * sin((PI * alfa) / 180), 100, 65 * cos((PI * alfa) / 180));//top of the cylinder
glVertex3f(15 * sin((PI * alfa) / 180),0, 15 * cos((PI * alfa) / 180));//base of the cylinder
}
glEnd();
glPopMatrix();
glPopMatrix();
glFlush();
}
void CALLBACK myReshape(GLsizei w, GLsizei h)
{
if (!h) return;
glViewport(0, 0, w, h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
if (w <= h)
glOrtho (-400,400, -400 *(GLfloat)h / (GLfloat)w, +400.0*(GLfloat)h/(GLfloat)w, -1000.0, 1000.0);
else
glOrtho (-400*(GLfloat)w / (GLfloat)h, 400.0*(GLfloat)w/(GLfloat)h, -400, 400.0, -1000.0, 1000.0);
glMatrixMode(GL_MODELVIEW);
}
int main(int argc, char** argv)
{
auxInitDisplayMode (AUX_SINGLE | AUX_RGB | AUX_DEPTH);
auxInitPosition (100, 0, 600, 400);
auxInitWindow ("Hot air balloon");
myinit ();
auxKeyFunc(AUX_RIGHT, rotateRight);
auxKeyFunc(AUX_LEFT, rotateLeft);
auxReshapeFunc (myReshape);
auxMainLoop(display);
return(0);
}
OpenGL is a state engine. Once a state has been set, it is retained until it is changed again, even beyond frames. Therefore, you need to set the polygon mode GL_FILL before rendering the solid geometry:
void CALLBACK display (void)
{
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
// render solid geometry
// [...]
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
// render wireframe geometry
// [...]
}
#include <stdio.h> // this library is for standard input and output
#include "glut.h"// this library is for glut the OpenGL Utility Toolkit
#include <math.h>
float squareX = 0.0f;
float squareY = -0.3f;
float squareZ = 0.0f;
static int flag = 1;
void drawShape(void) {
glTranslatef(squareX, squareY, squareZ);
glBegin(GL_POLYGON);
glColor3f(1.0, 0.0, 0.0);
glVertex2f(162, 50);
glVertex2f(162, 10);
glVertex2f(220, 10);
glVertex2f(220, 50);
glVertex2f(162, 50);
glEnd();
}
void initRendering() {
glEnable(GL_DEPTH_TEST);
}
// called when the window is resized
void handleResize(int w, int h) {
glViewport(0, 0, w, h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0.0f, (float)w, 0.0f, (float)h, -1.0f, 1.0f);
}
void drawScene() {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
drawShape();
glutSwapBuffers();
}
// make the square go up
void update(int value) {
if (flag) {
squareY += 1.0f;
if (squareY > 400.0) {
flag = 0;
}
}
glutPostRedisplay();
glutTimerFunc(25, update, 0);
}
// make the square go right
/* void update(int value) {
if (flag) {
squareX += 1.0f;
if (squareX > 400.0) {
flag = 0;
}
}
glutPostRedisplay();
glutTimerFunc(25, update, 0);
} */
int main(int argc, char** argv) {
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
glutInitWindowSize(400, 400);
glutCreateWindow("Moving Square");
initRendering();
glutDisplayFunc(drawScene);
glutReshapeFunc(handleResize);
glutTimerFunc(25, update, 0);
glutMainLoop();
return(0);
}
I have uploaded this code before but this time I made the square go all the way up. The code just moves the square up, but I don't know how to position it on the left once it reaches the top, so then I can make it move to the right. I have uploaded a demonstration on how I want it to look below.
Preview:
What I want it to do next:
I recommend to initialize the variables squareX, squareY and squareZ with the start position of the rectangle:
float squareX = 162.0f;
float squareY = 0.0f;
float squareZ = 0.0f;
Do not draw a rectangle specific position, but draw a rectangle on the position (0,0) with a length (width, height). Let the model matrix (set by glTranslatef), do the job of the positioning:
void drawShape(void)
{
float width = 58.0f;
float height = 40.0f;
glTranslatef(squareX, squareY, squareZ);
glBegin(GL_POLYGON);
glColor3f(1.0, 0.0, 0.0);
glVertex2f(0, 0);
glVertex2f(width, 0);
glVertex2f(width, height);
glVertex2f(0, height);
glVertex2f(0, 0);
glEnd();
}
Use a variable state, which has stated the direction of the current movement:
int state = 1; // 0: stop; 1: move up; 2: move right
If the rectangle a certain position has reached, then the state has to be changed and a the new start position can be set. At the final position, the rectangle can stop or the process can even be restarted:
void update(int value)
{
if (state == 1) // 1 : move up
{
squareY += 1.0f;
if (squareY > 400.0)
{
state = 2;
squareX = 0.0f;
squareY = 180.0f;
}
}
else if (state == 2) // 2 : move right
{
squareX += 1.0f;
if (squareX > 400.0)
{
state = 0;
// restart
//state = 1;
//squareX = 162.0f;
//squareY = 0.0f;
}
}
glutPostRedisplay();
glutTimerFunc(25, update, 0);
}
I'm currently doing an assignment in OpenGL and what I'm supposed to do is make two disks and then as I move the cursor on the screen and click the two disks should move to that position where I click on the window but the trick is that both the disks should not move together. The first disk should move and then after a small delay the second disk should move. Now I have been able to make both the disks move together at the point I click. What I want to know is how am I supposed to add a delay in the movement of both the disks. Please help!
This is my current code. Thanks!
EDIT:
Here's my updated code after implementing exactly what you said and now none of the disks are moving. If you understand the problem, fine otherwise thanks for all the help :)
#include <math.h>
#include <cstdlib>
#include <glut.h>
typedef struct _Vector
{
double x,y,z;
} Vector;
const int W_SCREEN = 1366;
const int H_SCREEN = 768;
const double PI = 3.14159265;
GLUquadric *qobja;
double speed = 10;
double radian;
double rot;
Vector pos2;
Vector pos;
Vector vel;
Vector dis;
Vector dir;
Vector mousecoords;
void mouse(int button, int state, int x , int y)
{
mousecoords.x = x - W_SCREEN/2;
mousecoords.y = -y + H_SCREEN/2;
}
void move()
{
dis.x = mousecoords.x - pos.x;
dis.y = mousecoords.y - pos.y;
if(sqrt(dis.x*dis.x + dis.y*dis.y) < speed)
{
pos.x = mousecoords.x;
pos.y = mousecoords.y;
pos2.x = mousecoords.x;
pos2.y = mousecoords.y;
}
else
{
radian = atan2(dis.y,dis.x);
pos.x += cos(radian)*speed;
pos.y += sin(radian)*speed;
pos2.x += cos(radian)*speed;
pos2.y += sin(radian)*speed;
}
}
void moveSecondDisk(int value)
{
// Code that moves (updates coordinates) of second disk
move();
glutPostRedisplay();
}
void moveFirstDisk(int value)
{
// Code that moves (updates coordinates) of first disk
move();
glutPostRedisplay();
unsigned int secondDiskDelay = 5000;
glutTimerFunc(secondDiskDelay, moveSecondDisk, 0);
}
void display(void)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glOrtho(-W_SCREEN/2,W_SCREEN/2,-H_SCREEN/2,H_SCREEN/2,-100,100);
qobja = gluNewQuadric();
gluQuadricNormals(qobja, GLU_SMOOTH);
glPushMatrix();
glColor3f(0,0,0);
glTranslated(pos.x,pos.y,0);
gluCylinder(qobja,25,50,0,100,100);
glPopMatrix();
glPushMatrix();
glColor3f(0,0,0);
glTranslated(pos2.x,pos2.y,0);
gluCylinder(qobja,50.5,65,0,100,100);
glPopMatrix();
/*glPushMatrix();
glColor3f(0,0,0);
glTranslated(pos.x,pos.y,0);
gluCylinder(qobja,65.5,80,0,100,100);
glPopMatrix();
glPushMatrix();
glColor3f(0,0,0);
glTranslated(pos.x,pos.y,0);
gluCylinder(qobja,80.5,90,0,100,100);
glPopMatrix();
glPushMatrix();
glColor3f(0,0,0);
glTranslated(pos.x,pos.y,0);
gluCylinder(qobja,90.5,100,0,100,100);
glPopMatrix();
glPushMatrix();
glColor3f(0,0,0);
glTranslated(pos.x,pos.y,0);
gluCylinder(qobja,100.5,110,0,100,100);
glPopMatrix();
glPushMatrix();
glColor3f(0,0,0);
glTranslated(pos.x,pos.y,0);
gluCylinder(qobja,110.5,120,0,100,100);
glPopMatrix();
glPushMatrix();
glColor3f(0,0,0);
glTranslated(pos.x,pos.y,0);
gluCylinder(qobja,120.5,130,0,100,100);
glPopMatrix();
glPushMatrix();
glColor3f(0,0,0);
glTranslated(pos.x,pos.y,0);
gluCylinder(qobja,130.5,140,0,100,100);
glPopMatrix();
glPushMatrix();
glColor3f(0,0,0);
glTranslated(pos.x,pos.y,0);
gluCylinder(qobja,140.5,150,0,100,100);
glPopMatrix();
glPushMatrix();
glColor3f(0,0,0);
glTranslated(pos.x,pos.y,0);
gluCylinder(qobja,150.5,160,0,100,100);
glPopMatrix();
glPushMatrix();
glColor3f(0,0,0);
glTranslated(pos.x,pos.y,0);
gluCylinder(qobja,160.5,170,0,100,100);
glPopMatrix();*/
glFlush();
glutSwapBuffers();
glutPostRedisplay();
}
void init(void)
{
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
glutInitWindowSize(W_SCREEN,H_SCREEN);
glutCreateWindow("ORCA WHALE SIMULATION");
glutDisplayFunc(display);
glutMouseFunc(mouse);
unsigned int firstDiskDelay = 2000;
glutTimerFunc(firstDiskDelay, moveFirstDisk, 0);
glClearColor(1,1,1,1);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glMatrixMode(GL_MODELVIEW);
}
int main(int argc, char** argv)
{
glutInit(&argc, argv);
init();
glutMainLoop();
return(0);
}
Use a timer to accomplish this. Create a function that moves the second disk with the following signature:
void moveSecondDisk(int value);
Then, execute the code that moves the first disk. Finally, call function glutTimerFunc, passing it the function moveSecondDisk as callback (second parameter). The first parameter will be delay between moving of two discs (expressed in miliseconds), and the third one will be value that is passed the callback function. Note that you can pass complex data to callback function by passing a pointer to a complex structure (or an object) as an integer, then casting it back to the desired type in the callback function. For more info, check the following links:
https://www.opengl.org/resources/libraries/glut/spec3/node64.html
https://www.opengl.org/discussion_boards/showthread.php/170990-glutTimerFunc
EDIT:
A more detailed explanation:
void movePos()
{
// Code that only modifies pos
...
}
void movePos2()
{
// Code that only modifies pos2
...
}
void moveSecondDisk(int value)
{
movePos2();
glutPostRedisplay();
}
void moveFirstDisk(int value)
{
movePos();
glutPostRedisplay();
unsigned int secondDiskDelay = 200;
glutTimerFunc(secondDiskDelay, moveSecondDisk, 0);
glutTimerFunc(300, moveFirstDisk, 0);
}
void init()
{
...
unsigned int firstDiskDelay = 50;
glutTimerFunc(firstDiskDelay, moveFirstDisk, 0);
...
}
So I have this creature and I want to have three distinct modes, a solid, a wireframe and both. All examples using glOffset did not seem to work for me.
Here's my display:
// This function is called to display the scene.
void display()
{
//Background color
glClearColor(1, 1, 1, 0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glEnable(GL_DEPTH_TEST);
// Matrix setup
glMatrixMode(GL_PROJECTION);
glViewport(0, 0, width, height);
glLoadIdentity();
gluPerspective(40, (float)width / (float)height, 0.1, 1000);
// Matrix setup
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(0, 0, -3);
//draw object
glBegin(GL_TRIANGLES);
for (int i = 0; i<mesh->nfaces.size(); i += 1)
for (int j = 0; j<3; j += 1){
glNormal3f(mesh->normal[mesh->nfaces[i][j]][0],
mesh->normal[mesh->nfaces[i][j]][1],
mesh->normal[mesh->nfaces[i][j]][2]);
glVertex3f(mesh->vertex[mesh->faces[i][j]][0],
mesh->vertex[mesh->faces[i][j]][1],
mesh->vertex[mesh->faces[i][j]][2]);
}
glEnd();
glutSwapBuffers();
}
Keyboard code where I tried to implement the shenanigans:
void keyboard(unsigned char key, int x, int y)
{
float colorBronzeDiff[4] = { 0.8, 0.6, 0.0, 1.0 };
switch (key)
{
case(27) :
exit(0);
break;
case('s') :
{
int myFlagCtr = getFlagCtr();
cout << "Pressed Before: " << getFlagCtr() << endl;
if (myFlagCtr == 0) {
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
setFlagCtr(1);
}
else if (myFlagCtr == 1) {
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
setFlagCtr(2);
}
else if (myFlagCtr == 2) {
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
glEnable(GL_POLYGON_OFFSET_FILL);
glPolygonOffset(1.0f, 1.0f);
glColor3f(0.0f, 1.0f, 0.0f);
// draw
glDisable(GL_POLYGON_OFFSET_FILL);
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
//glEnable( GL_POLYGON_OFFSET_LINE );
//glPolygonOffset( -2.0f, -2.0f );
glColor3f(1.0f, 0.0f, 0.0f);
glLineWidth(1.0f);
// draw
//glDisable( GL_POLYGON_OFFSET_LINE );
setFlagCtr(0);
cout << "Pressed Before: " << getFlagCtr() << endl;
}
break;
}
}
}
And here's main:
void main(int argc, char **argv)
{
// GLUT initialization.
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
glutInitWindowSize(width, height);
glutCreateWindow("CodeBase");
// Register call backs.
initialize();
glutDisplayFunc(display);
glutReshapeFunc(reshapeMainWindow);
glutMotionFunc(mouse_motion);
glutIdleFunc(idle);
glutKeyboardFunc(keyboard);
glutMouseFunc(mouse_button);
// Enter GLUT loop.
glutMainLoop();
delete mesh;
}
I assume what I am supposed to do is draw the image twice and then offset it, but for the life of me I can't seem to get this to work. I can't get it to show such a mode by default by putting it directly in display and attempting to draw the object twice.
Edit: In response to latest answer.
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
glEnable(GL_POLYGON_OFFSET_FILL);
glPolygonOffset(1.0f, 1.0f);
glColor3f(0.0f, 1.0f, 0.0f);
// draw
//draw object
glBegin(GL_TRIANGLES);
for (int i = 0; i<mesh->nfaces.size(); i += 1)
for (int j = 0; j<3; j += 1){
glNormal3f(mesh->normal[mesh->nfaces[i][j]][0],
mesh->normal[mesh->nfaces[i][j]][1],
mesh->normal[mesh->nfaces[i][j]][2]);
glVertex3f(mesh->vertex[mesh->faces[i][j]][0],
mesh->vertex[mesh->faces[i][j]][1],
mesh->vertex[mesh->faces[i][j]][2]);
}
glEnd();
glDisable(GL_POLYGON_OFFSET_FILL);
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
glColor3f(1.0f, 0.0f, 0.0f);
glLineWidth(1.0f);
// draw
//draw object
glBegin(GL_TRIANGLES);
for (int i = 0; i<mesh->nfaces.size(); i += 1)
for (int j = 0; j<3; j += 1){
glNormal3f(mesh->normal[mesh->nfaces[i][j]][0],
mesh->normal[mesh->nfaces[i][j]][1],
mesh->normal[mesh->nfaces[i][j]][2]);
glVertex3f(mesh->vertex[mesh->faces[i][j]][0],
mesh->vertex[mesh->faces[i][j]][1],
mesh->vertex[mesh->faces[i][j]][2]);
}
glEnd();
If you want the image to render in both wireframe and solid mode you have to actually execute the geometry rendering functions (eg: glBegin() ... glEnd()) twice.
In your third setting in the keyboard callback you call
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
But you don't draw any geometry between those two calls. GL is a state machine so only the last change to a given state (in this case the polygon drawing mode) will impact the rendering.
your setFlagCtr call should be in the keyboard callback function, but all the other stuff should be in the draw function where for the wire + solid mode you'll have to make sure you're calling this section at least twice:
glBegin(GL_TRIANGLES);
...
glEnd();
Long story short, don't put GL state or rendering management calls anywhere but your display function.
I'm following the xoax.net tutorials for OpenGL in C++, and I am stuck on drawing the stripes in the U.S. flag using a for loop. I just get a blue screen (since I set the background colour to blue). Here is the code for the 'DrawStripes' function:
void DrawStripes() {
for (int x = 0; x < 13; ++x) {
if (x % 2 == 0) {
glColor3f(204/255, 0, 0);
} else {
glColor3f(1, 1, 1);
}
float fStartX = 0;
float fEndX = 1;
float fStartY = x * (1/13);
float fEndY = (x + 1) * (1/13);
if (x > 5) {
fStartX = .76/1.9;
}
glBegin(GL_QUADS);
glVertex3f(fStartX, fStartY, 0);
glVertex3f(fEndX, fStartY, 0);
glVertex3f(fEndX, fEndY, 0);
glVertex3f(fStartX, fEndY, 0);
glEnd();
}
}
(I have put this function in the 'draw' function so it isn't just I'm not telling it to use the function)
Any ideas?
--- EDIT ---
Here are the 'Draw' and 'Initialize' functions:
void Draw() {
glClear(GL_COLOR_BUFFER_BIT);
DrawStripes();
glFlush();
}
void Initialize() {
glClearColor(0.0, 0.0, 0.5, 0.0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0.0, 1.0, 0.0, 1.0, -1.0, 1.0);
}
1/13 is 0 in C++. Been there, done that. For float constants you want to use 1.0f/13.0f.