Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (539)
Games in Android Showcase (132)
games submitted by our members
Games in WIP (603)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Help understanding the code  (Read 814 times)
0 Members and 1 Guest are viewing this topic.
Offline daimous

Junior Newbie





« Posted 2009-12-12 15:01:45 »

Hi Guys hel please.. I'm new to open gl programming ...Can any body please help me or at least give me idea on what subdivideCircle, normalize, and drawtriangle functions is trying to do? Thanks ina advance!

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
  // subdivide a triangle recursively, and draw them
    private void subdivideCircle(int radius, float[] v1, float[] v2, int depth)
    {
        float v11[] = new float[3];
        float v22[] = new float[3];
        float v00[] = {0, 0, 0};
        float v12[] = new float[3];
        if (depth==0)
        {
            //5. specify a color related to triangle location
            gl.glColor3f(v1[0]*v1[0], v1[1]*v1[1], v1[2]*v1[2]);
            for (int i = 0; i<3; i++)
            {
                v11[i] = v1[i]*radius;
                v22[i] = v2[i]*radius;
            }
            drawtriangle(v11, v22, v00);
            return;
        }
        v12[0] = v1[0]+v2[0];
        v12[1] = v1[1]+v2[1];
        v12[2] = v1[2]+v2[2];
        normalize(v12);
        // subdivide a triangle recursively, and draw them
        subdivideCircle(radius, v1, v12, depth-1);
        subdivideCircle(radius, v12, v2, depth-1);
    }

    // draw a circle with center at the origin in xy plane
    public void drawCircle(int cRadius, int depth)
    {
        subdivideCircle(cRadius, cVdata[0], cVdata[1], depth);
        subdivideCircle(cRadius, cVdata[1], cVdata[2], depth);
        subdivideCircle(cRadius, cVdata[2], cVdata[3], depth);
        subdivideCircle(cRadius, cVdata[3], cVdata[0], depth);
    }

    // normalize a 3D vector
    public void normalize(float vector[])
    {
        float d = (float)Math.sqrt(vector[0]*vector[0]
        +vector[1]*vector[1] + vector[2]*vector[2]);
        if (d==0)
        {
            System.out.println("0 length vector: normalize().");
            return;
        }
        vector[0] /= d;
        vector[1] /= d;
        vector[2] /= d;
    }

    public void drawtriangle(float[] v1, float[] v2, float[] v3)
    {
        gl.glBegin(GL.GL_TRIANGLES);
        gl.glVertex3fv(v1);
        gl.glVertex3fv(v2);
        gl.glVertex3fv(v3);
        gl.glEnd();
    }
Offline Eli Delventhal

JGO Kernel


Medals: 42
Projects: 11
Exp: 10 years


Game Engineer


« Reply #1 - Posted 2009-12-12 23:34:21 »

If you can't figure it out yourself, you're probably in trouble anyway. Just use the functions and don't worry about what's under the hood, or start from the beginning and learn OpenGL from  the ground up. One or the other.

Also, Off Topic is the wrong forum for this. Moved.

See my work:
OTC Software
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

rwatson462 (30 views)
2014-12-15 09:26:44

Mr.CodeIt (23 views)
2014-12-14 19:50:38

BurntPizza (49 views)
2014-12-09 22:41:13

BurntPizza (83 views)
2014-12-08 04:46:31

JscottyBieshaar (44 views)
2014-12-05 12:39:02

SHC (58 views)
2014-12-03 16:27:13

CopyableCougar4 (56 views)
2014-11-29 21:32:03

toopeicgaming1999 (122 views)
2014-11-26 15:22:04

toopeicgaming1999 (112 views)
2014-11-26 15:20:36

toopeicgaming1999 (32 views)
2014-11-26 15:20:08
Resources for WIP games
by kpars
2014-12-18 10:26:14

Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!