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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T03:47:13+00:00 2026-06-16T03:47:13+00:00

Nearly every OpenGL tutorial lets you implement drawing a cube. Therefore the vertices of

  • 0

Nearly every OpenGL tutorial lets you implement drawing a cube. Therefore the vertices of the cube are needed. In the example code I saw a long list defining every vertex. But I would like to compute the vertices of a cube rather that using a overlong list of precomputed coordinates.

A cube is made of eight vertices and twelve triangles. Vertices are defined by x, y, and z. Triangles are defined each by the indexes of three vertices.

Is there an elegant way to compute the vertices and the element indexes of a cube?

  • 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-06-16T03:47:14+00:00Added an answer on June 16, 2026 at 3:47 am

    When i was “porting” the csg.js project to Java I’ve found some cute code which generated cube with selected center point and radius. (I know it’s JS, but anyway)

    // Construct an axis-aligned solid cuboid. Optional parameters are `center` and
    // `radius`, which default to `[0, 0, 0]` and `[1, 1, 1]`. The radius can be
    // specified using a single number or a list of three numbers, one for each axis.
    // 
    // Example code:
    // 
    //     var cube = CSG.cube({
    //       center: [0, 0, 0],
    //       radius: 1
    //     });
    CSG.cube = function(options) {
      options = options || {};
      var c = new CSG.Vector(options.center || [0, 0, 0]);
      var r = !options.radius ? [1, 1, 1] : options.radius.length ?
               options.radius : [options.radius, options.radius, options.radius];
      return CSG.fromPolygons([
        [[0, 4, 6, 2], [-1, 0, 0]],
        [[1, 3, 7, 5], [+1, 0, 0]],
        [[0, 1, 5, 4], [0, -1, 0]],
        [[2, 6, 7, 3], [0, +1, 0]],
        [[0, 2, 3, 1], [0, 0, -1]],
        [[4, 5, 7, 6], [0, 0, +1]]
      ].map(function(info) {
        return new CSG.Polygon(info[0].map(function(i) {
          var pos = new CSG.Vector(
            c.x + r[0] * (2 * !!(i & 1) - 1),
            c.y + r[1] * (2 * !!(i & 2) - 1),
            c.z + r[2] * (2 * !!(i & 4) - 1)
          );
          return new CSG.Vertex(pos, new CSG.Vector(info[1]));
        }));
      }));
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In nearly every model, I end up writing code similar to the below example
Nearly every example I see of OpenGL ES involves it updating every frame, even
I've got some code that runs on every (nearly) every admin request but doesn't
I read through nearly every library linking tutorial but none worked for my specific
I recently inherited some C# code where nearly every item in a file was
I hate seeing nearly every directory in my repository list each file twice, once
I have read nearly every single post about the activity not found to handle
Is there a user-management plugin for grails? Nearly every website requires things like: Users
I have looked for an answer for this nearly every where that I can
For nearly every integration test, a user has to be signed into Devise. This

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.