Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4273820
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T07:45:51+00:00 2026-05-21T07:45:51+00:00

#include std_lib_facilities.h #include <GL/glut.h> static float dx=0.0; static float dz=10; static float points[2]; static

  • 0
#include "std_lib_facilities.h"
#include <GL/glut.h>

static float dx=0.0;
static float dz=10;
static float points[2];
static float cx=0.0;
static float cy=0.0;
static float cz=0.0;
static float spin=0.0;
static float rotation=1.0;


int readObject()
{

    ifstream inputFile("spikeBall.ogl");

    if(!inputFile)
    {
        cerr << "cannot open file spikeBall.ogl" << endl;
        return -1;
    }
    int count = 0;
    float x,y,z;

    do{
        inputFile >> count;
        glBegin(GL_POLYGON);
        for(int i=0;i<count;i++)
        {
            inputFile >> x >> y >> z;
            glVertex3f(((x/5)+cx),((y/5)+cy),((z/5)+cz));
        }
        glEnd();

    }while(count!=0);

    inputFile.close();
}

void init(void)
{
    glClearColor(0.0,0.0,0.0,0.0);
}

void display(void)
{
    glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glEnable(GL_DEPTH_TEST);

    glLoadIdentity();
    gluLookAt (0,0,20, 0.0,0.0,0.0, 0.0,1.0,0.0);

    glPushMatrix();

    glEnable(GL_LIGHTING);
    glEnable(GL_LIGHT0);

    GLfloat aMaterial[]={0.1745,0.01175,0.01175,1.0};
    GLfloat bMaterial[]={0.61424,0.04136,0.04136,1.0};
    GLfloat cMaterial[]={0.727811,0.626959,0.626959,1.0};
    GLfloat dMaterial=40;

    glMaterialfv(GL_FRONT,GL_AMBIENT,aMaterial);
    glMaterialfv(GL_FRONT,GL_DIFFUSE,bMaterial);
    glMaterialfv(GL_FRONT,GL_SPECULAR,cMaterial);
    glMaterialf(GL_FRONT,GL_SHININESS,dMaterial);

    readObject();
    glRotatef(spin,0.0,1.0,0.0);

    glPopMatrix();
    glFlush();
}

void idleFunc(void)
{
    spin+=rotation;
    if(spin>360.0)
    {
        spin-=360.0;
    }
    cz+=0.1;
    if(cz=20)
    {
        srand((unsigned int) time(NULL));
        for(int i=0;i<2;i++)
        {
            points[i] = (rand()%20)-10;
        }
        cx = points[0];
        cy = points[1];
        cz = 0;
        GLfloat lightPos[] = {cx,cy,(cz+2),1.0};
        glLightfv(GL_LIGHT0,GL_POSITION,lightPos);
        std::cout << "cx:" << cx;
        std::cout << "cy:" << cy;
        std::cout << "cz:" << cz;
    }
    else
    {
    }
    glutPostRedisplay();
}

void reshape (int w, int h)
{
    glViewport (0, 0, (GLsizei) w, (GLsizei) h);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluPerspective(60.0, (GLfloat) w/(GLfloat) h, 1.0,20.0);
    glMatrixMode(GL_MODELVIEW);
}

int main(int argc, char** argv)
{
    glutInit(&argc,argv);
    glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH);
    glutInitWindowSize(300,300);
    glutInitWindowPosition(0,0);
    glutCreateWindow("3ds Max loader");
    glutDisplayFunc(display);
    glutReshapeFunc(reshape);
    init();
    glutIdleFunc(idleFunc);
    glutMainLoop();
    return(0);
}

i made a spiky sphere in 3ds max then exported it as .obj and through some python i got an .ogl file i want it to move forward towards the screen before returning to a random point on the x and y axis, but it just keeps bouncing around

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T07:45:51+00:00Added an answer on May 21, 2026 at 7:45 am
    cz+=0.1;
    if(cz=20)
    {
      [random generator code]
    }
    

    Two problems here:

    First you’re assigning (=) 20 to cz instead of comparing (==) – even worse, this evaluates to true and triggers the code inside the brackets all the time. You should perhaps consider switching the compiler to a more verbose warning mode and/or reading the warnings more carefully.

    Second you should never compare floats with strict equality but using <= or >= because you will most probably miss the point because of floating point arithmetic – see this link f.e. if you’re unfamiliar with that problem. So the corrected code should look like this:

    cz += 0.1;
    if (cz >= 20)
    {
       [...]
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have such a program: #include <stdlib.h> #include <iostream> static int pswd=0; int main()
#include<stdlib.h> #include<string.h> #include<stdio.h> int pstrcmp( char **p,char **q) { return strcmp(*p,*q) ; } int
I've used #include<stdlib> #include<time> using namespace std; srand((unsigned)time(0)); int n=(rand()>>8)%4; but what other random
I created a program called test: #include<stdlib.h> #include<iostream> int main() { std::cout<<system(..\\add\\debug\\add.exe 4 8);
#include <stdio.h> #include <stdlib.h> #include <time.h> void initDeck (int deck[]); void showDeck (int deck[]);
#include<stdio.h> #include<string.h> #include<stdlib.h> int main() { // int char str[40],ch; FILE*fp,*fp1,*fp2; fp=fopen(ide_input,w); fp1=fopen(error_log,w); fp2=fopen(lex_output,w);
#include<stdio.h> #include<signal.h> #include<stdlib.h> void handler(int signo) { printf(First statement); system(date); exit(EXIT_SUCCESS); } int main()
#include <string.h> #include <stdlib.h> #include <stdio.h> int main(void) { unsigned char *stole; unsigned char
What is wrong with this program? #include <memory> #include <vector> int main() { std::vector<std::unique_ptr<int>>
using the following code: #include<iostream> #include<vector> using namespace std; int main() { vector<int> ivec;

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.