コード例 #1
0
ファイル: GraphicsSystem.cpp プロジェクト: Alucard014/OBS
void GraphicsSystem::Vertex(const Vect &v)
{
    if(!bNormalSet && vbd->NormalList.Num())
        Normal(vbd->NormalList[vbd->NormalList.Num()-1]);
    bNormalSet = 0;

    /////////////////
    if(!bColorSet && vbd->ColorList.Num())
        Color(vbd->ColorList[vbd->ColorList.Num()-1]);
    bColorSet = 0;

    /////////////////
    for(DWORD i=0; i<TexCoordSetList.Num(); i++)
    {
        if(!TexCoordSetList[i] && vbd->UVList[i].Num())
        {
            List<UVCoord> &UVList = vbd->UVList[i];
            TexCoord(UVCoord(UVList[UVList.Num()-1]), i);
        }
        TexCoordSetList.Clear(i);
    }

    vbd->VertList << v;

    ++dwCurPointVert;
}
コード例 #2
0
            void BoxUVModifier::Modify(TriangleBuffer& Buffer)
            {
                static const Vector3 Directions[6] = { Vector3::Unit_X(), Vector3::Unit_Y(), Vector3::Unit_Z(), Vector3::Neg_Unit_X(), Vector3::Neg_Unit_Y(), Vector3::Neg_Unit_Z()  };

                for( VertexIterator VertIt = Buffer.GetVertices().begin() ; VertIt != Buffer.GetVertices().end() ; ++VertIt )
                {
                    Vector3 VertPos = VertIt->Position - this->BoxPosition;
                    if( !VertPos.IsZeroLength() ) {
                        //VertPos.Normalize();
                        VertPos.X /= ( this->BoxHalfExtents.X * 2.0 );
                        VertPos.Y /= ( this->BoxHalfExtents.Y * 2.0 );
                        VertPos.Z /= ( this->BoxHalfExtents.Z * 2.0 );
                        Vector3 VertNorm = VertIt->Normal;
                        Real MaxAxis = 0;
                        Integer PrincipalAxis = 0;
                        for( UInt8 AxisIndex = 0 ; AxisIndex < 6 ; ++AxisIndex )
                        {
                            if( Directions[AxisIndex].DotProduct(VertNorm) > MaxAxis ) {
                                MaxAxis = Directions[AxisIndex].DotProduct(VertNorm);
                                PrincipalAxis = AxisIndex;
                            }
                        }

                        Vector3 vX, vY;
                        if( PrincipalAxis % 3 == 1 ) {
                            vY = Vector3::Unit_X();
                        }else{
                            vY = Vector3::Unit_Y();
                        }
                        vX = Directions[PrincipalAxis].CrossProduct(vY);

                        Vector2 UVCoord( 0.5 - vX.DotProduct(VertPos), 0.5 - vY.DotProduct(VertPos) );
                        if( this->Mapping == BoxUVModifier::MT_Full ) {
                            VertIt->UV = UVCoord;
                        }else if( this->Mapping == BoxUVModifier::MT_Cross ) {
                            // Too lazy to think of a more elegant solution
                            switch( PrincipalAxis )
                            {
                                case 1:  VertIt->UV = Vector2( ( UVCoord.X + 2 ) / 4, ( UVCoord.Y + 1 ) / 3 );  break;  // 3,2
                                case 2:  VertIt->UV = Vector2( ( UVCoord.X + 1 ) / 4, UVCoord.Y / 3 );          break;  // 2,1
                                case 3:  VertIt->UV = Vector2( ( UVCoord.X + 3 ) / 4, ( UVCoord.Y + 1 ) / 3 );  break;  // 4,2
                                case 4:  VertIt->UV = Vector2( UVCoord.X / 4, ( UVCoord.Y + 1 ) / 3 );          break;  // 1,2
                                case 5:  VertIt->UV = Vector2( ( UVCoord.X + 1 ) / 4, ( UVCoord.Y + 2 ) / 3 );  break;  // 2,3
                                case 6:  VertIt->UV = Vector2( ( UVCoord.X + 1 ) / 4, ( UVCoord.Y + 1 ) / 3 );  break;  // 2,2
                            }
                        }else if( this->Mapping == BoxUVModifier::MT_Packed ) {
                            VertIt->UV = Vector2( ( UVCoord.X + PrincipalAxis % 3 ) / 3, ( UVCoord.Y + PrincipalAxis / 3 ) / 2 );
                        }
                    }
                }
            }
コード例 #3
0
ファイル: pigment.cpp プロジェクト: carolemieux/daikon
int Compute_Pigment (COLOUR Colour, PIGMENT *Pigment, VECTOR EPoint, INTERSECTION *Intersect)
{
  int Colour_Found;
  VECTOR TPoint;
  DBL value;
  register DBL fraction;
  BLEND_MAP_ENTRY *Cur, *Prev;
  COLOUR Temp_Colour;
  BLEND_MAP *Blend_Map = Pigment->Blend_Map;
  UV_VECT UV_Coords;

  if (Pigment->Type <= LAST_SPECIAL_PATTERN)
  {
    Colour_Found = true;

    switch (Pigment->Type)
    {
      case NO_PATTERN:

        Make_Colour(Colour, 0.0, 0.0, 0.0);

        break;

      case PLAIN_PATTERN:

        Assign_Colour(Colour,Pigment->Colour);

        break;

      case AVERAGE_PATTERN:

        Warp_EPoint (TPoint, EPoint, (TPATTERN *)Pigment);

        Do_Average_Pigments(Colour,Pigment,TPoint,Intersect);

        break;

      case UV_MAP_PATTERN:
        if(Intersect == NULL)
           Error("The 'uv_mapping' pattern cannot be used as part of a pigment function!");

        Cur = &(Pigment->Blend_Map->Blend_Map_Entries[0]);

        if (Blend_Map->Type == COLOUR_TYPE)
        {
          Colour_Found = true;

          Assign_Colour(Colour, Cur->Vals.Colour);
        }
        else
        {
          /* Don't bother warping, simply get the UV vect of the intersection */
          UVCoord(UV_Coords, Intersect->Object, Intersect);
          TPoint[X] = UV_Coords[U];
          TPoint[Y] = UV_Coords[V];
          TPoint[Z] = 0;

          if (Compute_Pigment(Colour, Cur->Vals.Pigment,TPoint,Intersect))
          {
            Colour_Found = true;
          }
        }

        break;

      case BITMAP_PATTERN:

        Warp_EPoint (TPoint, EPoint, (TPATTERN *)Pigment);

        Make_Colour(Colour, 0.0, 0.0, 0.0);

        Colour_Found = image_map (TPoint, Pigment, Colour);

        break;

      default:

        Error("Pigment type %d not yet implemented",Pigment->Type);
    }

    return(Colour_Found);
  }

  Colour_Found = false;

  /* NK 19 Nov 1999 added Warp_EPoint */
	Warp_EPoint (TPoint, EPoint, (TPATTERN *)Pigment);
	value = Evaluate_TPat ((TPATTERN *)Pigment,TPoint,Intersect);

  Search_Blend_Map (value, Blend_Map, &Prev, &Cur);

  if (Blend_Map->Type == COLOUR_TYPE)
  {
    Colour_Found = true;

    Assign_Colour(Colour, Cur->Vals.Colour);
  }
  else
  {
    Warp_EPoint (TPoint, EPoint, (TPATTERN *)Pigment);

    if (Compute_Pigment(Colour, Cur->Vals.Pigment,TPoint,Intersect))
    {
      Colour_Found = true;
    }
  }

  if (Prev != Cur)
  {
    if (Blend_Map->Type == COLOUR_TYPE)
    {
      Colour_Found = true;

      Assign_Colour(Temp_Colour, Prev->Vals.Colour);
    }
    else
    {
      if (Compute_Pigment(Temp_Colour, Prev->Vals.Pigment, TPoint,Intersect))
      {
        Colour_Found = true;
      }
    }

    fraction = (value - Prev->value) / (Cur->value - Prev->value);

    Colour[pRED]    = Temp_Colour[pRED]    + fraction * (Colour[pRED]    - Temp_Colour[pRED]);
    Colour[pGREEN]  = Temp_Colour[pGREEN]  + fraction * (Colour[pGREEN]  - Temp_Colour[pGREEN]);
    Colour[pBLUE]   = Temp_Colour[pBLUE]   + fraction * (Colour[pBLUE]   - Temp_Colour[pBLUE]);
    Colour[pFILTER] = Temp_Colour[pFILTER] + fraction * (Colour[pFILTER] - Temp_Colour[pFILTER]);
    Colour[pTRANSM] = Temp_Colour[pTRANSM] + fraction * (Colour[pTRANSM] - Temp_Colour[pTRANSM]);
  }

  return(Colour_Found);
}