Title: Background node problems
We use nested skydomes in background geometry for our sky system.
 
Here are some relevant code snippets:
 
   /**
    * Builds the vertices needed for the sky dome.  This is not the same as the
    * geometry, since that needs to be constructed using a triangle fan and a bunch
    * of triangle strips.
    */
 
   private void buildVertices() {
 
      numVertices = 1 + 4 * resolution * resolution;
      vertices = new Point3f[numVertices];
 
      float radAngle = (90f - vertSweep) / 180f * (float)Math.PI;
      radius /= (float)Math.cos (radAngle);
 

      //
      // Compute the y adjustment
      //
 
      float yAdj = radius * (float)Math.sin( radAngle);
 
      //
      // From the resolution, compute the angular sweep of one section
      // of the dome
      //
 

      float horzSweep = (float)Math.toRadians(90.0f / resolution);
      vertSweep /= resolution;
      vertSweep = (float)Math.toRadians(vertSweep);
 
      //
      // Start the vertex list with the very top of the dome
      //
 
      vertices[0] = new Point3f(0, (radius - yAdj) * heightScale,0);
      vertices[0].add(origin);
 
      int nVertex = 1;
      for (int i = 0; i < resolution; i++)
      {
 
         //
         // Compute the vertex that will be rotated around to make a ring
         //
 
         Point3f vPoint = new Point3f(0, radius, 0);
         Matrix3f m = new Matrix3f();
         m.rotZ(vertSweep * (i + 1));
         m.transform(vPoint);
         vPoint.y = (vPoint.y - yAdj) * heightScale;
 
         //
         // Loop through the ring creating the points
         //
 
         for (int j = 0; j < resolution * 4; j++)
         {
 
            //
            // Map the point
            //
 
            m.rotY (horzSweep * j);
            vertices[nVertex] = new Point3f();
            m.transform (vPoint, vertices[nVertex]);
            vertices[nVertex].add(origin);
            nVertex++;
         }
      }
 
   }
 
   private void computeCounts() {
 
      numStripVertices = 0;
      numFanVertices =  resolution * 4 + 1 + 1;
      numStrips = resolution-1;
      stripCount = new int[numStrips];
 
      //
      // Loop through squares
      //
 
      numStripVertices = 0;
      int nDelta = resolution * 4;
      for (int j = 1; j < resolution; j++) {
 
         stripCount[j-1] = 0;
         int nStart = nDelta * j + 1;
         int nEnd = nStart + nDelta;
 
         for (int i = nStart; i < nEnd; i++) {
            stripCount[j-1] += 2;
         }
         stripCount[j-1] += 2;
         numStripVertices += stripCount[j-1];
      }
 
      Log.log.println(LogType.EXHAUSTIVE, "SKY: Number of vertices in dome is "+numStripVertices);
 
   }
 
 
We create two grometry arrays per layer.  One is a fan and one is strips:
 
    gFan = new FanGeomHolder(GeomHolder.GEOM_TRI_FAN,mode,dome.numFanVertices,1,s);
 
      // build the geometry holder for the strips which are the rest of the dome
 
      gStrips = new StripGeomHolder(GeomHolder.GEOM_TRI_STRIP,mode,dome.numStripVertices,1,dome.stripCount);
 
 
For drawing the fan:
 
     drawStart();
         drawCoord(dome.vertices[0], this);
         for (int i = 1; i < dome.resolution * 4+1; i++)
            drawCoord(dome.vertices[i], this);
         drawCoord(dome.vertices[1], this);
 
For drawing the strips:
 
      drawStart();
 
         int nDelta = dome.resolution * 4;
         for (int j = 1; j < dome.resolution; j++)
         {
            int nStart = nDelta * j + 1;
            int nEnd = nStart + nDelta;
            for (int i = nStart; i < nEnd; i++)
            {
               drawCoord(dome.vertices[i - nDelta], this);
               drawCoord(dome.vertices[i], this);
            }
            drawCoord(dome.vertices[nStart - nDelta], this);
            drawCoord(dome.vertices[nStart], this);
         }
 
         drawEnd();
 
 
 
Tex coords are a bit tricky, but here is some relevent code.  We have multiple layers moving at different speeds:
 
  public void computePosition( float timeInDays, float dayFactor, int timeType ) {
 
      offset.set(speed);
//      offset.normalize();
      offset.x *= timeInDays;
      offset.y *= timeInDays;
 
      // set everything up for the texture coordinate generation
 
      tscale = 1.0f / (dome.radius * 2.0f * scale);
      sTexShift = 0.5f + speed.x * timeInDays;
      tTexShift = 0.5f + speed.y * timeInDays;
      sTexture.set(tscale,0,0);
      tTexture.set(0,0,tscale);
 
      if (transitionExp != 1.0f)
         dayFactor = (float)Math.pow (dayFactor, transitionExp);
      if (dayFactor>1) dayFactor = 1;
      else if (dayFactor<0) dayFactor=0;
 
      if (dayFactor==0) curColor.set(nightColor);
      else if (dayFactor==1) curColor.set(dayColor);
      else curColor.interpolate(nightColor,dayColor,dayFactor);
 
      if (hasAlpha) {
         if (curColor.w==0) rapp.setVisible(false);
         else rapp.setVisible(true);
      }
 
   }
 
 
And the translation into the coord itself:
 
  void drawCoord( Point3f p, GeomHolder g ) {
 
      g.newVertex();
      if (!verticesSet) g.setCoordinate(p);
      g.setColor(curColor);
 
      // compute the texture coordinate
 
      vpoint.set(p);
      texCoord.x = vpoint.dot(sTexture) + sTexShift;
      texCoord.y = vpoint.dot(tTexture) + tTexShift;
      g.setTexCoord(texCoord);
 
   }
 
 
Hope that helps.
 
Dave Yazel
 
-----Original Message-----
From: Smith, Daniel [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, May 15, 2002 10:44 AM
To: [EMAIL PROTECTED]
Subject: [JAVA3D] Background node problems

I'm working on  Background node geometry, and I don't want to waste CPU with those extra Sphere polys below the horizon that will never be seen...

I'm trying to create a slightly flattened, low-poly hemisphere for a skybox/cloud layer, and I want it as background so the Fog node won't affect it (if there's a work-around let me know!).  I have this working as normal geometry, but fogging is very inconsistent across the relatively large polygons that stretch into the distance...

Has anyone had luck creating background geometry other than a sphere?  Do all points have to live on (or within) 1.0 units from the origin? I can't find any good documentation on it, and every attempt I make results in no geometry being shown...

Also-anyone know of a good sphere or hemisphere geometry generating algorithm that can generate tex coords too (or be modified to do so?)

Scott

Reply via email to