C++ Program to Draw Circle of Desired Radius

  1. #1

    OneStiffRod is offline

    UNBANNED OneStiffRod's Avatar


    Best mode to depict circle!!??

    I'thousand creating mod's for this game and I need to know some things about 3D math...

    TRIGONOMETRY

    namely, the best way to draw a CIRCLE in a 3D game --

    Is it just a rotation about the X centrality?? or is there a improve way..
    If it is a rotation can u give me the best way as I would accept to create a loop and calculate for 360 degrees or do I take to even do more than than 360 calculations to brand it more beleivable??

    These links volition aid what I'm talking about -- the second deals more with the bodily game im working with.

    Basic 3D math
    http://toadlife.net/ofp/downloads/tu...trigguide.html

    My Avatar says: "Stay in School"

    Rocco is the Boy!
    "Close YOUR LIPS..."


  2. #two

    confuted is offline

    Pursuing knowledge confuted's Avatar


    well, a circumvolve isn't a 3D shape. If you want to impose a circle on summit of the display, and then do the affair with the for loop. The number of steps you lot'll need depends on the size of the circle. If you want the circle in the globe...brand a model with a bunch of points in the shape of a circumvolve or something.


  3. #3

    MrWizard is offline

    Registered User


    So nosotros can employ Polar coordinates to notice the points on a circle given a distance from origin.

    We can then convert to rectangular coordinates as follows:

    x = r * cos( theta )
    y = r * sin( theta )

    Where r is the radius of the desired circumvolve and theta is the bending.
    (x,y) will exist your point on the given circumvolve.


  4. #iv

    doubleanti is offline

    Linguistic Engineer... doubleanti's Avatar


    Brensenham'southward (spelling?) circle (and line too) algorithm is quite constructive, only since you'd need to scale information technology for perspective maybe information technology wouldn't exist as effective.

    hasafraggin shizigishin oppashigger...


  5. #v

    CheesyMoo is offline

    The Pantless Man CheesyMoo's Avatar


    If you want to make a Circle, you can use the Borlan graphics library.


  6. #6

    SAMSAM is offline

    Registered User SAMSAM's Avatar


    If You were using Opengl You needed only one function
    &1 header.

    header GLAUX.H
    function auxSolidSphere(float);

    // rotation speed
    if (angle >= 359.0f)
    angle = 0.0f;
    bending += 0.two;

    Last edited by SAMSAM; 04-27-2003 at 07:12 PM.


  7. #vii

    SAMSAM is offline

    Registered User SAMSAM's Avatar


    similar this; three balls with a blending & lighting mix.
    Last edited past SAMSAM; 04-27-2003 at 07:28 PM.


  8. #8

    OneStiffRod is offline

    UNBANNED OneStiffRod's Avatar


    Ok,

    Thanx for all the advice just I think only MrWizard got what I was trying to inquire - for whatsoever standard shapes I will be using a graphics library like OpenGl or DX merely this is more almost formulas/algorithim'due south to produce the shapes.

    I'grand working in GAME SCRIPT and don't have the luxury of standard function calls to produce my affects.

    I was thinking that I will have to create a circumvolve using the formula
    x = r * cos( theta )
    y = r * sin( theta )
    , cheque the 2nd link in my start post to understand this formula.

    Using the above formula I volition accept to create a loop and calculate at least 360times to get the 360 caste values to produce a second(x,y) circle -- im not really after a 3D sphere shape.

    I wanna know if there is a better formula or just ameliorate manner to work the above formula then I don't accept to run through 360 loop cycles or fifty-fifty more to go 2nd pts around my target to create a circular blueprint?? For instance I know that there are quadrants I can work in when using degrees similar 0-90, tin I but run through the sin/cos calcs for 0-90 and somehow adjust the gotten values to and employ them to the next quadrant or is information technology only equally fast to calculate 360 sin/cos values??

    Code:

    //Psuedo-code as im not working in C++ targetPosition = <2341,3642,0> //3D Vector <x,y,z>  /*I need to find points at every bending at 300meters from my  *target'south position - the target's position volition be the center of the  *circle and 300 meters is the radius *Formula r*cos(theta) - r stands for radius */ //I merely need the 2nd coords A = 0;               //This is the angle - 0 - 360 r = 300;           //This is the radius targetXPos= 2341;  //Targets Ten position targetYPos= 3642;  //Targets Y position  #LOOP //In this loop we will calculate 360 times to go 360 points around our target for(A; A<=360;A++){    x = cos(A) * r;    y = sin(A) * r;     newXPos= targetXPos + ten;    newYPos= targetYPos + y; }

    My Avatar says: "Stay in School"

    Rocco is the Boy!
    "SHUT YOUR LIPS..."


  9. #ix

    MrWizard is offline

    Registered User


    I'm glad you asked. Y'all simply need to do 1/4 of the circle then the other 3 are variations of your original points. Lets say i of your points in the upper right part of a unit circle with center at origin is:

    We go from 0 to 90 to get upper right portion.
    ( 45 degrees example )

    x = .99
    y = .707

    Then the upper left would be

    x = -.99
    y = .707

    And so lower left:

    x = -.99
    y = -.707

    Then lower correct:

    x = .99
    y = -.707

    Looking for something like that?


  10. #x

    OneStiffRod is offline

    UNBANNED OneStiffRod's Avatar


    That's exactly right - just sin/cos already exercise that I judge - the same values are repeated just in dissimilar society and neg values...

    sooooo not sure whether splitting information technology up would brand up any time differences.

    My Avatar says: "Stay in Schoolhouse"

    Rocco is the Boy!
    "SHUT YOUR LIPS..."


  11. #11

    OneStiffRod is offline

    UNBANNED OneStiffRod's Avatar


    Let'south say I want to instead create a MATRIX 300 ten 300 -- in game...

    This will play out like an blithe-gif image so information technology's piece of cake all i accept is arrays filled with 2d vector points and the matrix is swapped over time so it plays as an blitheness..... simple.

    OK, how can I create this matrix and and so be able to "PASTE" it in anywhere in my 3D globe... the values in the matrix need to change according to where it'southward placed in game so I need advice on how to record the MATRIX values so they are easily changed.

    If I start at 0 on left hand side like a standard XY graph in my recorded MATRIX values, how do I change all the values in my MATRIX to correspond with a starting 2d vector of <2340,1355> on the left hand corner.

    ???

    PS--I call up this method will be significantly faster than computing each betoken using a loop...

    My Avatar says: "Stay in School"

    Rocco is the Boy!
    "SHUT YOUR LIPS..."


  12. #12

    SAMSAM is offline

    Registered User SAMSAM's Avatar


    Even if you lot shorten the loop by sectionalisation(break it into
    pies) you however need an inner loop to figure out the x&y coordinates
    in relation to those, in order to save them in betoken[360] array.

    dont we?.


  13. #xiii

    Silvercord is offline

    Banned


    hey mr stiffy, test the time it takes to run each loop. Obviously running through the commencement quadrant then setting points from there will be faster, but the other method will probably run and then fast it won't really matter.

    DWORD begintime, totaltime;
    begintime = GetTickCount();

    for(a ridiculously high number of times)
    dostuff();

    totaltime = GetTickCount - BeginTime();


gregorybinien02.blogspot.com

Source: https://cboard.cprogramming.com/game-programming/38632-best-way-draw-circle.html

0 Response to "C++ Program to Draw Circle of Desired Radius"

ارسال یک نظر

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel