void VRendererNodeHelper::InvalidateFrustum()
{
  V_SAFE_DELETE_ARRAY(m_pOverlayVertices);
  V_SAFE_DELETE_ARRAY(m_pOverlayVerticesHalfSize);

  m_bFrustumMeshBufferDirty = true;
}
void VRendererNodeHelper::DeInit()
{
  m_spMeshBuffer = NULL;
  m_spSphereMeshBuffer = NULL;
  m_spConeMeshBuffer = NULL;

  V_SAFE_DELETE_ARRAY(m_pOverlayVertices);
  V_SAFE_DELETE_ARRAY(m_pOverlayVerticesHalfSize);
}
void VRestoreScreen::GrabBackgroundScreenshot()
{
  const int iScreenWidth = Vision::Video.GetXRes();
  const int iScreenHeight = Vision::Video.GetYRes();

  // Write the frame buffer to memory buffer.
  V_SAFE_DELETE_ARRAY(m_pScreenshotBuffer);
  m_pScreenshotBuffer = new unsigned char[iScreenWidth*iScreenHeight*3];
  if (!Vision::Game.WriteScreenToBuffer(0, 0, iScreenWidth, iScreenHeight, static_cast<UBYTE*>(m_pScreenshotBuffer)))
  {
    V_SAFE_DELETE_ARRAY(m_pScreenshotBuffer);
  }
}
void MergedModelFactory_cl::DeleteModels()
{
  // Detach camera 
  m_pCameraEntity->DetachFromParent();

  // Delete model preview
  if (m_pPreviewModelEntities != NULL)
  {
    m_vPos = m_pPreviewModelEntities[0]->GetPosition();
    m_vOri = m_pPreviewModelEntities[0]->GetOrientation();

    for (int i = 0; i < BARBARIAN_MAX; i++)
      V_SAFE_DISPOSEOBJECT(m_pPreviewModelEntities[i]);
  }

  V_SAFE_DELETE_ARRAY(m_pPreviewModelEntities);

  // Delete merged model
  if (m_pMergedModelEntity != NULL)
  {
    m_vPos = m_pMergedModelEntity->GetPosition();
    m_vOri = m_pMergedModelEntity->GetOrientation();

    VDynamicMesh::GetResourceManager().RemoveResource(m_pMergedModelEntity->GetMesh());

    V_SAFE_DISPOSEOBJECT(m_pMergedModelEntity);
  }
}
  /// \brief
  ///   Assignment operator; assigns the texture smart pointers componentwise.
  VisSurfaceTextures_cl &operator = (const VisSurfaceTextures_cl &other)
  {
    if(this == &other)
      return *this;
  
    m_iIndex = other.m_iIndex;
    m_spDiffuseTexture = other.m_spDiffuseTexture;
    m_spNormalMap = other.m_spNormalMap;
    m_spSpecularMap = other.m_spSpecularMap;
    m_spModelLightmaps[0] = other.m_spModelLightmaps[0];
    m_spModelLightmaps[1] = other.m_spModelLightmaps[1];
    m_spModelLightmaps[2] = other.m_spModelLightmaps[2];
    m_spModelLightmaps[3] = other.m_spModelLightmaps[3];
    m_vLightmapScaleOfs = other.m_vLightmapScaleOfs;

    //copy auxiliary textures
    V_SAFE_DELETE_ARRAY(m_spAuxiliaryTextures);
    m_iAuxiliaryTextureCount = other.m_iAuxiliaryTextureCount;
    if (m_iAuxiliaryTextureCount>0)
    {
      int i;
      m_spAuxiliaryTextures = new VTextureObjectPtr[m_iAuxiliaryTextureCount];
      for (i=0;i<m_iAuxiliaryTextureCount;i++)
        m_spAuxiliaryTextures[i] = other.m_spAuxiliaryTextures[i];
    }


    return *this;
  }
Beispiel #6
0
VMemoryDataStream::~VMemoryDataStream()
{
    if (m_bCreated)
    {
        V_SAFE_DELETE_ARRAY(m_pBuffer);
        m_pBuffer = NULL;
    }
}
Beispiel #7
0
 /// \brief
 ///   Frees the allocated resources
 inline void FreeBitfield()
 {
   if (m_pField != m_OwnBits)
   {
     V_SAFE_DELETE_ARRAY(m_pField); 
   }
   m_iBitCount = 0;
   m_pField = m_OwnBits;
 }
RPG_MeshTrailEffectComponent::~RPG_MeshTrailEffectComponent()
{
  if (m_meshObj)
  {
    m_meshObj->DisposeObject();
  }

  V_SAFE_DELETE_ARRAY(m_history);
}
void VRestoreScreen::DeInit()
{
  Vision::Callbacks.OnBeforeSwapBuffers -= this;
  Vision::Callbacks.OnLeaveForeground -= this;
  Vision::Callbacks.OnEnterForeground -= this;
  Vision::Callbacks.OnEnterBackground -= this;

  V_SAFE_DELETE_ARRAY(m_pScreenshotBuffer);

  VLoadingScreenBase::DeInit();
}
bool VAppWin::CheckFullscreenResolution(int iAdapter, int desiredX, int desiredY, int* selectedX, int* selectedY)
{
  VASSERT(selectedX && selectedY);

  // by default is the same
  *selectedX = VVIDEO_DEFAULTWIDTH;
  *selectedY = VVIDEO_DEFAULTHEIGHT;

  // Getting the number of display modes
  DEVMODEA deviceMode;
  deviceMode = Vision::Video.GetAdapterMode(iAdapter);
  int nModes = VVideo::GetAdapterModeCount(iAdapter, deviceMode.dmBitsPerPel);

  if (nModes == 0)
    return false;

  // Retrieving the display modes
  VVideoMode* arrayModes = new VVideoMode[nModes];
  memset(arrayModes, 0, sizeof(VVideoMode)*nModes);
  VASSERT(arrayModes != NULL);
  VVideo::EnumAdapterModes(iAdapter, deviceMode.dmBitsPerPel, arrayModes);

  int iError = 1 << 16;
  VVideoMode* pBestFitting = NULL;
  for (int i=0; i<nModes; ++i)
  {
    const int iX = arrayModes[i].m_iXRes;
    const int iY = arrayModes[i].m_iYRes;

    // Same resolution mode exists, returns supported+
    if (iX == desiredX && iY == desiredY)
    {
      *selectedX = desiredX;
      *selectedY = desiredY;
      return true;
    }

    const int iValue = ((iX - desiredX)*(iX - desiredX) + (iY - desiredY)*(iY - desiredY)) / 2; // Mean Square Error
    if (iValue < iError)
    {
      pBestFitting = &arrayModes[i];
      iError = iValue;
    }
  }

  if (pBestFitting != NULL)
  {
    *selectedX = pBestFitting->m_iXRes;
    *selectedY = pBestFitting->m_iYRes;
  }
  V_SAFE_DELETE_ARRAY(arrayModes);

  return false;
}
Beispiel #11
0
void VMemoryDataStream::copy(const VMemoryDataStream &other)
{
    V_SAFE_DELETE_ARRAY(m_pBuffer);

    m_pBuffer = new uchar_t[other.m_lSize];
    memcpy(m_pBuffer, other.m_pBuffer, other.m_lSize);

    m_lSize = other.m_lSize;
    m_lCurPos = other.m_lCurPos;

    m_bCreated = true;
}
    /// \brief
    ///  Allocates iCount decoration instances in this list
    ///
    /// \param pOwner
    ///  Initializes each instance's m_pOwnerSector member
    ///
    /// \param iCount
    ///  Number of objects to allocate
    ///
    inline void Allocate(VTerrainSector *pOwner, int iCount)
    {
        if (m_iCount==iCount) return;
        V_SAFE_DELETE_ARRAY(m_pInstances);
        m_iCount = iCount;
        if (iCount<1)
            return;

        m_pInstances = new VTerrainDecorationInstance[m_iCount];
        for (int i=0; i<iCount; i++)
            m_pInstances[i].m_pOwnerSector = pOwner;
    }
void VRestoreScreen::OnHandleCallback(IVisCallbackDataObject_cl* pData)
{
  if (pData->m_pSender == &Vision::Callbacks.OnProgress)
  {
    // Only react to the message if it signals a background restore.
    VisProgressDataObject_cl* pPDO = (VisProgressDataObject_cl*)pData;
    if (pPDO->m_eType != VisProgressDataObject_cl::PDOT_BACKGROUND_RESTORE)
      return;
  }
  else if (pData->m_pSender == &Vision::Callbacks.OnBeforeSwapBuffers)
  {
    if (m_bGrab)
    {
      GrabBackgroundScreenshot();
      m_bGrab = false;
    }
  }
  else if (pData->m_pSender == &Vision::Callbacks.OnLeaveForeground)
  {
    // Only grab a screen shot if the application is currently running.
    if (VAppBase::Get()->GetAppState() == VAppHelper::AS_RUNNING)
    {
      m_bGrab = true;
    }
    else
    {
      // Otherwise copy loading screen settings from VLoadingScreen module (if present).
      VLoadingScreen* pLoadingScreenModule = GetParent()->GetAppModule<VLoadingScreen>();
      if (pLoadingScreenModule != NULL)
      {
        // But disable the fade out.
        Settings settings = pLoadingScreenModule->GetSettings();
        settings.m_fFadeOutTime = 0.0f;
        SetSettings(settings);
      }
    }
  }
  else if (pData->m_pSender == &Vision::Callbacks.OnEnterBackground)
  {
    // Save the screen shot only now to reduce the time spent in Vision::Callbacks.OnLeaveForeground.
    // This is critical on Android devices.
    SaveBackgroundScreenshot();
  }
  else if (pData->m_pSender == &Vision::Callbacks.OnEnterForeground)
  {
    // Reset screen shot grab state in case the application only went to the sleep state on Android.
    m_bGrab = false;
    V_SAFE_DELETE_ARRAY(m_pScreenshotBuffer);
  }

  VLoadingScreenBase::OnHandleCallback(pData);
}
 inline void SetLightMaskIndexList(int iCount, const int *pList)
 {
   V_SAFE_DELETE_ARRAY(m_pLightMaskEntryIndex);
   m_iNumLightMaskEntries = iCount;
   if (iCount>0)
   {
     m_pLightMaskEntryIndex = new int[iCount];
     if (pList)
       memcpy(m_pLightMaskEntryIndex,pList,sizeof(int)*iCount);
     else
       memset(m_pLightMaskEntryIndex,0,sizeof(int)*iCount);
   }
 }
MergedModelFactory_cl::~MergedModelFactory_cl()
{
  // Delete merged model
  if (m_pMergedModelEntity)
     V_SAFE_DISPOSEOBJECT(m_pMergedModelEntity);
  
  // Delete model preview
  if (m_pPreviewModelEntities != NULL)
    for (int i = 0; i < BARBARIAN_MAX; i++)
      V_SAFE_DISPOSEOBJECT(m_pPreviewModelEntities[i])

  V_SAFE_DELETE_ARRAY(m_pPreviewModelEntities);
}
Beispiel #16
0
	void VConsole::print(const char *pszFmt, ...)
	{
		if (NULL != m_pAdapter)
		{
			char *pszBuffer = new char[V_MAX_LOG_BUFFER_SIZE];
			memset(pszBuffer, 0, V_MAX_LOG_BUFFER_SIZE);

			va_list vl;
			va_start(vl, pszFmt);
			vsnprintf(pszBuffer, V_MAX_LOG_BUFFER_SIZE, pszFmt, vl);
			va_end(vl);

			m_pAdapter->print(pszBuffer);

			V_SAFE_DELETE_ARRAY(pszBuffer);
		}
	}
void VRestoreScreen::SaveBackgroundScreenshot()
{
  // GrabBackgroundScreenshot() needs to be called before
  if (m_pScreenshotBuffer == NULL)
    return;

  const int iScreenWidth = Vision::Video.GetXRes();
  const int iScreenHeight = Vision::Video.GetYRes();
  ColorCorrect(m_pScreenshotBuffer, iScreenWidth, iScreenHeight, m_fBrightness, m_fSaturation);

  // use VTEX to scale and save the image
  Image_cl image;
  ImageMap_cl colorMap(iScreenWidth, iScreenHeight, 24, static_cast<UBYTE*>(m_pScreenshotBuffer));
  image.AddColorMap(colorMap);

  // Decide which resolution to use for the saved image.
  int iScaledWidth = 512;
  while (iScaledWidth > iScreenWidth || iScaledWidth > iScreenHeight)
  {
    iScaledWidth /= 2;
    VASSERT(iScaledWidth > 0);
  }

  image.Scale(iScaledWidth, iScaledWidth);

  const char* szFilename = ":app_cache/vision_background.bmp";
  IVFileOutStream* pOut = Vision::File.Create(szFilename);
  const bool bSaved = (image.SaveBMP(pOut) == VERR_NOERROR);
  V_SAFE_DELETE_ARRAY(m_pScreenshotBuffer);

  if (pOut != NULL)
    pOut->Close();

  if (bSaved)
  {
    // Set up loading screen settings.
    Settings settings(szFilename);
    settings.m_eAspectRatioAlignment = ALIGN_NONE;
    SetSettings(settings);
  }
  else
  {
    hkvLog::Dev("VRestoreScreen: Could not save backgrounding screenshot\n");
  }
}
 /// \brief
 ///  Destructor
 virtual ~VTerrainDecorationInstanceCollection()
 {
     V_SAFE_DELETE_ARRAY(m_pInstances);
 }
Beispiel #19
0
 /// \brief
 ///   Releases all link information.
 inline void FreeLinks()
 {
   if (m_pLinks!=m_Buffer) V_SAFE_DELETE_ARRAY(m_pLinks);
   m_iLinkCount = 0;
 }
 inline void ResetStaticGeometryInstanceList()
 {
   m_iStaticGeometryInstanceCount = 0;
   V_SAFE_DELETE_ARRAY(m_pStaticGeometryInstanceList);
 }
 /// \brief
 ///  Releases allocated instances
 ///
 inline void Free()
 {
     m_iCount = 0;
     V_SAFE_DELETE_ARRAY(m_pInstances);
 }
 /// \brief
 ///   Resets the table
 inline void Reset() 
 {
   m_iEntryCount=0;V_SAFE_DELETE_ARRAY(m_pEntry);
 }
Beispiel #23
0
 /// \brief
 ///   Destructor. Releases all elements
 inline ~VRefCountedCollection() 
 {
   Clear();
   V_SAFE_DELETE_ARRAY(m_ppElements);
 }
 ~MeshMaterial_t()
 {
   V_SAFE_DELETE_ARRAY(m_pLightMaskEntryIndex);
   V_SAFE_DELETE_ARRAY(m_pIndices);
   V_SAFE_DELETE_ARRAY(m_pIndices32);
 }
// ReadPlacesFile: Reads in the PLACES_FILE and sets up all the WorldPlace_t
//                 objects.
void WorldLanguages_cl::ReadPlacesFile()
{
  IVFileInStream* pIn = Vision::File.Open(PLACES_FILE);
  char *buffer = NULL;
  
  if (pIn)
  {
    int fsize= pIn->GetSize();
    
    buffer = new char[fsize+1];
    pIn->Read(buffer, fsize);
    buffer[fsize] = 0;
    
    pIn->Close();
  }
  // if we couldn't read anything, return here!
  if (!buffer)
    return;

  static const char Newline[] = "\r\n";
  // tokenize buffer line-wise
  char *line = strtok(buffer, Newline);
  
  // skip first character, it only marks the UTF8 file (Byte Order Mark)
  line += 3;
  // read number of places
  sscanf(line, "%d", &m_iNumPlaces);
  // no places -> return without doing anything
  if (m_iNumPlaces < 1)
  {
    V_SAFE_DELETE_ARRAY(buffer);
    return;
  }
  // create m_iNumPlaces WorldPlace_t structs
  m_pPlaces = new WorldPlace_t[m_iNumPlaces];
  m_iCurrentPlace = 0;

  // get all places
  while (m_iCurrentPlace < m_iNumPlaces)
  {
    WorldPlace_t &pThisPlace = m_pPlaces[m_iCurrentPlace];
    // get next line
    line = strtok(NULL, Newline);
    if (line == NULL)
    {
      V_SAFE_DELETE_ARRAY(buffer);
      return;
    }

    // skip comments
    if (line[0] == ';')
      continue;
    // skip empty lines
    if (line[0] == '\0')
      continue;
    // find [
    if (line[0] == '[')
    {
      // the next line contains the name of the place
      line = strtok(NULL, Newline);
      pThisPlace.m_PlaceName = line;

      //is it Arabic?
      bool bArabic = strcmp(line, "UAE - Arabic") == 0;

      // the next line contains the font type
      line = strtok(NULL, Newline);

      // load font type with resource manager
      pThisPlace.m_spFont = Vision::Fonts.LoadFont(line);

      //left to right or right to left?
      line = strtok(line + strlen(line) + 1, Newline); // LoadFont() seems to use strtok too -> reinitialize
      bool bIsRightToLeft = strcmp(line,"RTL") == 0;

      // the next line contains the alphabet index, x position and y position
      // read alphabet, x_pos, y_pos;
      line = strtok(NULL, Newline);
      float x,y;
      sscanf(line, "%f,%f", &x, &y);
      
      // fix up angles (convert from long/lat to yaw/pitch)
      pThisPlace.m_angleY = -x;
      pThisPlace.m_angleZ = -y-90;
      // the next line(s) contain(s) the text
      // read text
      line = strtok(NULL, Newline);
      pThisPlace.m_Text.Reset();
      // until text is ]
      while (line[0] != ']')
      {
        pThisPlace.m_Text += line;
        pThisPlace.m_Text += "\n";
        line = strtok(NULL, Newline);
      }

      // Init Arabic support helper and set text which gets transformed from uniform to contextual Arabic
      if(bArabic)
      {
        pThisPlace.m_pRTLSupport = new VArabicSupport_cl(pThisPlace.m_spFont, pThisPlace.m_Text);
      }
      else if(bIsRightToLeft)
      {
        pThisPlace.m_pRTLSupport = new VRTLSupport_cl(pThisPlace.m_spFont, pThisPlace.m_Text);
      }

    }

    m_iCurrentPlace++;
  }
  V_SAFE_DELETE_ARRAY(buffer);

}
Beispiel #26
0
void VCurve2DBase::FreePoints()
{
  m_iNumCurvePoints = 0;
  V_SAFE_DELETE_ARRAY(m_pPoints);
}
// ----------------------------------------------------------------------------
bool vHavokCableConstraintChainRenderer::RebuildModel()
{
  m_spChainMesh = NULL;

  if (!m_pConstraintChain || !m_pConstraintChain->IsValid())
    return false;
  
  int iNumLinks = m_pConstraintChain->GetNumLinks();
  m_iLastKnownNumLinks = iNumLinks;

  if (iNumLinks < 1)
  {
    Vision::Error.Warning("vHavok: Can't create cable rendering - constraint chain has no links.");
    return false;
  }

  int iVerticesPerRing = hkvMath::Max(6, VerticesPerRing);
  int iRingsPerLink = hkvMath::Max(1, RingsPerLink);

//#define ENDS_ONLY

  // Vertices for each ring (final vertex is at the position of the first
  // vertex), times the number of rings
#ifdef ENDS_ONLY
  int iNumVertices = 0;
#else
  int iNumVertices = ((iNumLinks * iRingsPerLink) + 1) * (iVerticesPerRing + 1);
#endif
  // Extra vertices for the end surfaces
  iNumVertices += (iVerticesPerRing + 1) * 2;
  if (iNumVertices > 65535)
  {
    Vision::Error.Warning("vHavok: Can't create cable rendering - too many vertexes.");
    return false;
  }

#ifdef ENDS_ONLY
  int iNumTriangles = 0;
#else
  int iNumTriangles = iRingsPerLink * iNumLinks * iVerticesPerRing * 2;
#endif
  // Extra triangles for the end surfaces
  iNumTriangles += iVerticesPerRing * 2;

  float fRadius = m_pConstraintChain->GetDiameter() / 2.f;
  float fCircumference = fRadius * 2.0f * hkvMath::pi ();
  
  float fRingHeight = m_pConstraintChain->GetLinkLength() / iRingsPerLink;
  float fTextureVPerRing = fRingHeight / fCircumference;

  // Load the model that provides the surface material of the cable
  VDynamicMeshPtr spTemplateMesh;
  if (!ModelFile.IsEmpty())
    spTemplateMesh = VDynamicMesh::LoadDynamicMesh(ModelFile);

  // Pre-calculate the coordinates, normals and texture offsets of the ring
  // and end cap vertices
  hkvVec3* rgvVertexTemplates = new hkvVec3[iVerticesPerRing + 1];
  hkvVec3* rgvNormalTemplates = new hkvVec3[iVerticesPerRing + 1];
  float *rgfTextureU = new float[iVerticesPerRing + 1];
  hkvVec2* rgvEndTexCoords = new hkvVec2[iVerticesPerRing];
  {
    float fMaxEndTexOffset = 1.f / (2.0f * hkvMath::pi ());
    for (int i = 0; i < iVerticesPerRing; ++i)
    {
      float fRatio = (float)i / (float)iVerticesPerRing;
      float fAngle = fRatio * 2.0f * hkvMath::pi ();
      rgvNormalTemplates[i].set(0.f, hkvMath::cosRad (fAngle), hkvMath::sinRad (fAngle));
      rgvVertexTemplates[i] = rgvNormalTemplates[i] * fRadius;
      rgfTextureU[i] = fRatio;
      rgvEndTexCoords[i].set(
        0.5f + (hkvMath::cosRad (fAngle) * fMaxEndTexOffset),
        0.5f + (hkvMath::sinRad (fAngle) * fMaxEndTexOffset));
    }
    rgvNormalTemplates[iVerticesPerRing] = rgvNormalTemplates[0];
    rgvVertexTemplates[iVerticesPerRing] = rgvVertexTemplates[0];
    rgfTextureU[iVerticesPerRing] = 1.f;
  }


  VColorRef cableColor(V_RGBA_YELLOW);
  hkvVec3 vTangent(1.f, 0.f, 0.f);

  int usageFlags = VIS_MEMUSAGE_STREAM;
  int bindFlags = VIS_BIND_SHADER_RESOURCE;
  
#ifdef _VR_DX11
  // Only specify this flag if this is a true DX11 card, since the engine currently
  // just passes it along to the device. This fails if the feature is not supported.
  // It is needed for Compute Shader Skinning
  if (Vision::Video.GetDXFeatureLevel() >= D3D_FEATURE_LEVEL_11_0)
  {
    usageFlags |= VIS_MEMUSAGE_UAV_BYTEADDRESS;
    bindFlags |= VIS_BIND_UNORDERED_ACCESS;
  }
#endif

  VDynamicMeshBuilder meshBuilder(iNumVertices, iNumTriangles, iNumLinks + 2, 1, usageFlags, bindFlags);

  if (spTemplateMesh && (spTemplateMesh->GetSurfaceCount() > 0))
    meshBuilder.CopySurfaceFrom(0, *spTemplateMesh->GetSurface(0));

#ifndef ENDS_ONLY
  for (int iCurrentLink = 0; iCurrentLink < iNumLinks; ++iCurrentLink)
  {
    /// The vertices of a chain link are influenced by three bones.
    int iPrevBone = iCurrentLink;
    int iThisBone = iCurrentLink + 1;
    int iNextBone = iCurrentLink + 2;

    /// The last link has an additional ring of vertices at its end
    int iLocalNumRings = iCurrentLink == (iNumLinks - 1)
      ? iRingsPerLink + 1 : iRingsPerLink;

    /// Compute the vertices for each ring of the current chain link:
    for (int iCurrentRing = 0; iCurrentRing < iLocalNumRings; ++iCurrentRing)
    {
      /// Normalized offset of this ring from the start of the chain link (range 0..1)
      float fNormOffset = (float)iCurrentRing / (float)iRingsPerLink;

      /// Calculate the influence factors of the three bones that might affect
      /// the current ring
      float fPrevBoneWeight = hkvMath::Max(0.f, 0.5f - fNormOffset);
      float fThisBoneWeight = 1.f - hkvMath::Abs (fNormOffset - 0.5f);
      float fNextBoneWeight = hkvMath::Max(0.f, fNormOffset - 0.5f);

      /// Compute the vertices of one ring. The start/end vertices are at the same
      /// position, since two different texture coordinates are needed here.
      int iStartVertex = meshBuilder.GetNextVertexIndex();
      for (int iLocalVertex = 0; iLocalVertex <= iVerticesPerRing; ++iLocalVertex)
      {
        hkvVec3 vPos(rgvVertexTemplates[iLocalVertex]);

        // Texture v coordinate increases throughout the chain
        float fTextureV = ((iCurrentLink * iRingsPerLink) + iCurrentRing) * fTextureVPerRing;
        hkvVec2 vTexCoords(rgfTextureU[iLocalVertex], fTextureV);

        // Add vertex data...
        int iCurrentVertex = meshBuilder.AddVertex(vPos, 
          rgvNormalTemplates[iLocalVertex], vTangent, vTexCoords, cableColor);
        VASSERT(iCurrentVertex >= 0);

        // ...and bone weights.
        if (fPrevBoneWeight > 0.f)
          meshBuilder.AddBoneWeight(iPrevBone, fPrevBoneWeight);
        meshBuilder.AddBoneWeight(iThisBone, fThisBoneWeight);
        if (fNextBoneWeight > 0.f)
          meshBuilder.AddBoneWeight(iNextBone, fNextBoneWeight);

        // Unless we are at the last vertex in a ring or at the last ring of the
        // last link, compute the vertex indices that make up the triangles for 
        // the cable.
        if ((iCurrentRing < iRingsPerLink) && (iLocalVertex < iVerticesPerRing))
        {
          unsigned short i1, i2, i3;
          int iNextRing = iStartVertex + iVerticesPerRing + 1;

          i1 = iStartVertex + iLocalVertex;
          i2 = iStartVertex + iLocalVertex + 1;
          i3 = iNextRing + iLocalVertex;
          meshBuilder.AddTriangle(i1, i2, i3);

          i1 = iStartVertex + iLocalVertex + 1;
          i2 = iNextRing + iLocalVertex + 1;
          i3 = iNextRing + iLocalVertex;
          meshBuilder.AddTriangle(i1, i2, i3);
        }

        //iCurrentVertex++;
      } // End of vertex loop
    } // End of rings per chain link loop
  } // End of chain link loop
#endif

  // Add the end surfaces
  {
    hkvVec3 vEndNormal = hkvVec3(-1.f, 0.f, 0.f);
    hkvVec3 vEndTangent = hkvVec3(0.f, 1.f, 0.f);

    // Center vertex (Top)
    int iCenterVertexIndex = meshBuilder.GetNextVertexIndex();
    meshBuilder.AddVertex(hkvVec3::ZeroVector (), vEndNormal, 
      vEndTangent, hkvVec2 (0.5f, 0.5f), cableColor);
    meshBuilder.AddBoneWeight(0, 0.5f);
    meshBuilder.AddBoneWeight(1, 0.5f);

    // Outer vertices (Top)
    int iStartVertexIndex = meshBuilder.GetNextVertexIndex();
    for (int iLocalVertex = 0; iLocalVertex < iVerticesPerRing; ++iLocalVertex)
    {
      meshBuilder.AddVertex(rgvVertexTemplates[iLocalVertex],
        vEndNormal, vEndTangent, rgvEndTexCoords[iLocalVertex], cableColor);
      meshBuilder.AddBoneWeight(0, 0.5f);
      meshBuilder.AddBoneWeight(1, 0.5f);
      int iNextLocalVertex = iLocalVertex + 1;
      if (iNextLocalVertex == iVerticesPerRing)
        iNextLocalVertex = 0;

      meshBuilder.AddTriangle(iCenterVertexIndex, 
        iStartVertexIndex + iLocalVertex, iStartVertexIndex + iNextLocalVertex);
    }


    // Bottom cap: normal points the other way (tangent remains)
    vEndNormal.set(1.f, 0.f, 0.f);

    // Center vertex (Bottom)
    iCenterVertexIndex = meshBuilder.GetNextVertexIndex();
    meshBuilder.AddVertex(hkvVec3::ZeroVector (), vEndNormal, 
      vEndTangent, hkvVec2 (0.5f, 0.5f), cableColor);
    meshBuilder.AddBoneWeight(iNumLinks, 0.5f);
    meshBuilder.AddBoneWeight(iNumLinks + 1, 0.5f);

    // Outer vertices (Top)
    iStartVertexIndex = meshBuilder.GetNextVertexIndex();
    for (int iLocalVertex = 0; iLocalVertex < iVerticesPerRing; ++iLocalVertex)
    {
      meshBuilder.AddVertex(rgvVertexTemplates[iLocalVertex],
        vEndNormal, vEndTangent, rgvEndTexCoords[iLocalVertex], cableColor);
      meshBuilder.AddBoneWeight(iNumLinks, 0.5f);
      meshBuilder.AddBoneWeight(iNumLinks + 1, 0.5f);
      int iNextLocalVertex = iLocalVertex + 1;
      if (iNextLocalVertex == iVerticesPerRing)
        iNextLocalVertex = 0;

      meshBuilder.AddTriangle(iCenterVertexIndex, 
        iStartVertexIndex + iLocalVertex, iStartVertexIndex + iNextLocalVertex);
    }
  }

  V_SAFE_DELETE_ARRAY(rgvVertexTemplates);
  V_SAFE_DELETE_ARRAY(rgvNormalTemplates);
  V_SAFE_DELETE_ARRAY(rgfTextureU);
  V_SAFE_DELETE_ARRAY(rgvEndTexCoords);

  VASSERT(meshBuilder.GetNextVertexIndex() == iNumVertices);
  VASSERT(meshBuilder.GetNextIndexIndex() == (iNumTriangles * 3));

  m_spChainMesh = meshBuilder.Finalize();
  VASSERT(m_spChainMesh);

  // Create the entity and the animation state
  if (!m_spChainEntity)
  {
    m_spChainEntity = static_cast<vHavokCableConstraintChainEntity*>(
      Vision::Game.CreateEntity("vHavokCableConstraintChainEntity", hkvVec3::ZeroVector ()));
  }
  m_spChainEntity->SetConstraintChain(m_pConstraintChain);
  m_spChainEntity->SetMesh(m_spChainMesh);
  m_spChainEntity->SetCastShadows(CastDynamicShadows);

  VisAnimFinalSkeletalResult_cl* pFinalSkeletalResult;
  VisAnimConfig_cl* pAnimConfig = VisAnimConfig_cl::CreateSkeletalConfig(m_spChainMesh, &pFinalSkeletalResult);
  m_spChainEntity->SetAnimConfig(pAnimConfig);

  return true;
}
 ~VisSurfaceTextures_cl()
 {
   V_SAFE_DELETE_ARRAY(m_spAuxiliaryTextures);
 }
void AnimatedWarrior_cl::InitFunction()
{
  SetCastShadows(TRUE);
  
  SetupAnimations();
  if (!m_bModelValid)
    return;

	m_pCharacterController = new vHavokCharacterController();
	m_pCharacterController->Initialize();

	hkvAlignedBBox bbox;
	GetMesh()->GetCollisionBoundingBox(bbox);

  float r = bbox.getSizeX() * 0.5f;
	m_pCharacterController->Capsule_Radius = r;
	m_pCharacterController->Character_Top.set(0,0,bbox.m_vMax.z - r);
  m_pCharacterController->Character_Bottom.set(0,0,bbox.m_vMin.z + r);

 	m_pCharacterController->Max_Slope = 75.0f;

  if (!m_bEnabled)
    m_pCharacterController->SetEnabled(FALSE);

	AddComponent(m_pCharacterController);

  //// setup animation system
  // create config
  VDynamicMesh* pMesh = GetMesh();
  VASSERT(pMesh);
  VisSkeleton_cl* pSkeleton = pMesh->GetSkeleton();
  VASSERT(pSkeleton);

  // create mixer structure, we keep pointers on the mixers to add and remove inputs
  m_spLayerMixer = new VisAnimLayerMixerNode_cl(pSkeleton);

  m_pNormalizeMixer = new VisAnimNormalizeMixerNode_cl(pSkeleton);
  m_spLayerMixer->AddMixerInput(m_pNormalizeMixer, 1.f);

  //// create per bone weighting list for upper body
  int iBoneCount = pSkeleton->GetBoneCount();
  float* fPerBoneWeightingList = new float[iBoneCount];
  memset(fPerBoneWeightingList, 0, sizeof(float)*iBoneCount);

  // set all bone weights above the spine to 1
  pSkeleton->SetBoneWeightRecursive(1.f, pSkeleton->GetBoneIndexByName("skeleton1:Spine"), fPerBoneWeightingList);

  int iMixerInputIndex = -1;

  for(int i=0; i<UPPERBODY_CONTROLCOUNT; i++)
  {
    m_spUpperBodyControls[i] = new VisSkeletalAnimControl_cl(pSkeleton, VSKELANIMCTRL_DEFAULTS);
    m_spUpperBodyControls[i]->AddEventListener(this); // we want to receive all events from sequence and control
    iMixerInputIndex = m_spLayerMixer->AddMixerInput(m_spUpperBodyControls[i], 0.f);
    m_spLayerMixer->ApplyPerBoneWeightingMask(iMixerInputIndex, iBoneCount, fPerBoneWeightingList);
  }
  
  V_SAFE_DELETE_ARRAY(fPerBoneWeightingList);

  // set the start animation
  BlendOverFullBodyAnimation(0.f, ANIMID_IDLE, 1.f, 0.f);
 
  SetFullBodyState(m_pFullBodyIdleState[FBSTATETYPE_NORMAL]);
  SetUpperBodyState(m_pUpperBodyIdleState);

  // initialize variables for upperbody fadein/fadeout
  m_eUpperBodyFadeState = FADESTATE_NONE;

  // setup neck bone for head rotation
  m_iHeadBoneIndex = pSkeleton->GetBoneIndexByName("skeleton1:Neck");
  m_fHeadRotationAngles[0] = 0.f; m_fHeadRotationAngles[1] = 0.f; m_fHeadRotationAngles[2] = 0.f;
  m_bHeadInMovement = false;

  // setup the torch
  hkvVec3 vDummyOrigin;
  m_pTorch = (AttachedTorch_cl *) Vision::Game.CreateEntity( "AttachedTorch_cl", vDummyOrigin );
  
  HideTorch();

  // attach the torch to the bone
  //hkvVec3 localTranslation(-11.f, -4.5f, 25.f);
  hkvVec3 localTranslation(-11.f, 5.5f, 0.f);
  float euler[3] = {90, 0, 185};
  hkvQuat localRotation;
  localRotation.setFromEulerAngles (euler[2], euler[1], euler[0]); // pass as roll, pitch, yaw
  m_pTorch->Attach(this, "skeleton1:RightHand", localRotation, localTranslation);

  SetEnabled(true);
}
Beispiel #30
0
void VCurve2DBase::FreeLookup()
{
  m_iLookupCount = 0;
  V_SAFE_DELETE_ARRAY(m_pLookupValues);
}