Procedural landscapes: Total n0ob needs to streamline maths code

This is a discussion on Procedural landscapes: Total n0ob needs to streamline maths code within the C Programming forums, part of the General Programming Boards category; I have a code that generates mountain shapes for 10 different 3d maps covering an entire graph, then i delete ...

  1. #1
    Registered User
    Join Date
    May 2011
    Posts
    4

    Procedural landscapes: Total n0ob needs to streamline maths code

    I have a code that generates mountain shapes for 10 different 3d maps covering an entire graph, then i delete 90 percent of each map and mix the rest into a final map with a variety of mountain shapes. Therefore processor useage is 9 times inefficent! The code can make infinite variety of basic shapes and mixes.

    The graphics engine asks height information for X,Y, and the code returns Z using sine functions.

    graph axes X and Y are Floats in the range -1,1.

    How can make variables new_X and new_Y that are only segments of X,Y, So that i can code sin(new_X)*sin(new_Y), and it will calculate mountains only in the ranges that will be visible in the final map? for example new_X would be a segment of X in the range (-0.1,0.2) that exists on the X variable.
    Attached Images Attached Images     
    Last edited by stylistically; 05-05-2011 at 03:39 AM.

  2. #2
    Registered User
    Join Date
    Mar 2011
    Posts
    261
    If X and Y are ints, a look-up table might speed up the sin function. Usually the tradeoff is more memory used for implementing the table, but less processing time.

    As to limiting of the number of calcs to a given "zone", I don't understand your algorithm as you presented it. There's a capital Y and a small y, capital Z and small z. How about either some descriptions, or better, more descriptive variable names?

  3. #3
    Registered User
    Join Date
    May 2011
    Posts
    4
    Thanks!

    Sorry i have rewritten the explanation more clearly. the X and Y axes are Floats in the range -1 to 1, but i could convert everything to integer, which i believe is faster on x86. A sin lookup table would be awesome, i will do some reading!

    I would still love to know how to make a segments of a variable where code is only processed for those segments, so that you can process different maths on each segment of a variable, rather than having to do the maths on the entire range and then delete the rest and mix the remainder, like how i am doing.
    Last edited by stylistically; 05-05-2011 at 03:32 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. what is a minimum code for maths functions
    By arazki1yes in forum C Programming
    Replies: 1
    Last Post: 04-05-2011, 05:18 AM
  2. Procedural Noise and OpenGL Help!
    By Freestyler in forum C Programming
    Replies: 8
    Last Post: 04-18-2008, 09:06 AM
  3. Switching from procedural to OOP
    By Thantos in forum A Brief History of Cprogramming.com
    Replies: 6
    Last Post: 04-04-2004, 11:08 PM
  4. OO vs. Procedural Programming
    By Speedy5 in forum Tech Board
    Replies: 23
    Last Post: 03-15-2004, 10:08 AM
  5. OOP v Procedural
    By NickESP in forum C++ Programming
    Replies: 7
    Last Post: 02-08-2003, 06:46 AM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21