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 6804349
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T19:27:18+00:00 2026-05-26T19:27:18+00:00

I am trying to implement a camera controlled scene using the camera code from:

  • 0

I am trying to implement a camera controlled scene using the camera code from: http://www.swiftless.com/tutorials/opengl/camera2.html

And the landscape code from a book, which randomly generates terrain. By using the code as shown below, the mouse controls and the landscape work BUT the landscape keeps randomly generating ALL the time. I suspect this is to do with the IdleFunc, but if I take that line from main() out, the mouse stops working.

How can I separate the camera and the land to work independently?

 void display() 
    {
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
        glLoadIdentity();

        camera();
        landscape.draw();

        glutSwapBuffers();
    }

in Main:

// callback methods
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutIdleFunc(display);
glutPassiveMotionFunc(mouseMovement);

land.cpp:

void land::draw(void)
{
   int i;
   size = 1;
   for (i=1;i<=numlevels;i++) size = size * 2;
   for (i=0;i<=size;i++) cd[i] = (GLfloat)i/(GLfloat)size;
   twotopowerh = exp(log(2.0)*hvalue);
   cvalue = 1.0*sqrt(1.0 - twotopowerh*twotopowerh/4.0);
   if (!sea) {
       calcheights();
       makesmooth();
   }
   drawmesh();
   drawsides();
   if (sea) {
       drawsea();
       sea = 0;
   }
}
  • 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-26T19:27:18+00:00Added an answer on May 26, 2026 at 7:27 pm

    Indeed that landscape drawing code regenerates the geometry each time it’s called. All that’s code in land::draw, except drawmesh(), drawsides() and drawsea() should be placed in the constructor or a initializer. Only the drawing calls should be made from a drawing function.


    Edit: Modification of provided code

    land.hpp

    class land : …
    {
    // ...
    public:
        void generate(void);
    // ...
    }
    

    land.cpp

    void land::generate(void)
    {
       int i;
       size = 1;
       for (i=1;i<=numlevels;i++) size = size * 2;
       for (i=0;i<=size;i++) cd[i] = (GLfloat)i/(GLfloat)size;
       twotopowerh = exp(log(2.0)*hvalue);
       cvalue = 1.0*sqrt(1.0 - twotopowerh*twotopowerh/4.0);
       if (!sea) {
           calcheights();
           makesmooth();
       }
    }
    
    void land::draw(void)
    {
       drawmesh();
       drawsides();
       if (sea) {
           drawsea();
           sea = 0;
       }
    }
    

    In Main

    glutDisplayFunc(display);
    glutReshapeFunc(reshape);
    
    // better just issue a redisplay, allows for smoother input event processing
    glutIdleFunc(glutPostRedisplay);
    
    glutPassiveMotionFunc(mouseMovement);
    
    landscape.generate();
    
    // ...
    
    glutMainLoop();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to implement Camera application in android,and i got some code from
trying to implement a multiplayer. Using the sample from Game Center - Sending and
I am trying implement the Data transformation using Reflection 1 example in my code.
I'm trying to implement a stereo camera calibration app using emgu cv. My problem
I'm trying to implement Pinch Zoom in my app using a 2d camera. I
trying to implement a dialog-box style behaviour using a separate div section with all
Am trying to implement a generic way for reading sections from a config file.
I'm trying to display a UIImage in real-time coming from the camera, and it
Found a really nice code for Accordion nav and am trying implement on our
I am trying to implement face recognition on camera captured faces.In order to make

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.