Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

gl_sphir_tex_coord_gen.C

Go to the documentation of this file.
00001 #include "gl_sphir_tex_coord_gen.H"
00002 
00003 
00004 
00005 
00006 void
00007 GLSphirTexCoordGen ::setup()
00008 {
00009 }
00010 
00011 UVpt
00012 GLSphirTexCoordGen ::compute_uv(CBvert *v)
00013 {
00014   //computes spherical 2d texture coordinates
00015   //in object coordinates
00016    Wvec n = v->loc() - Wpt(0,0,0);  
00017    n = n.normalized(); 
00018 
00019    double alpha = atan2(n[2],n[0]); 
00020    double theta = acos(n[1]);
00021 
00022    UVpt tex_coord = UVpt((alpha / (TWO_PI) ) + 0.5, (theta / TWO_PI) + 0.5);
00023    
00024    return tex_coord;
00025 }
00026 
00027 
00028 UVpt
00029 GLSphirTexCoordGen ::uv_from_vert(CBvert *v, CBface *f)
00030 {
00031    //in object coordinates
00032 
00033    UVpt tex_coord = compute_uv(v);
00034 
00035    Bvert* t1 = f->v1();
00036    Bvert* t2 = f->v2();
00037    Bvert* t3 = f->v3();
00038 
00039    UVpt ts1;
00040    UVpt ts2;
00041    
00042    //grab the two other UV coordinates for this face
00043    
00044    if (t1 == v)
00045    {
00046       ts1 = compute_uv(t2);
00047       ts2 = compute_uv(t3);
00048    }
00049    else
00050    {
00051       ts1 = compute_uv(t1);
00052       if (t2 == v)
00053          ts2 = compute_uv(t3);
00054       else
00055          ts2 = compute_uv(t2);
00056    }
00057 
00058   
00059    return fix_seems(tex_coord,ts1,ts2);
00060 }
00061 
00062 // end of file gl_sphir_tex_coord_gen.C

Generated on Mon Sep 18 11:39:30 2006 for jot by  doxygen 1.4.4