Beispiel #1
0
  void NgammaT::calcVelScale(){

    for (int i = 0; i < 3; i++ ) {
      for (int j = 0; j < 3; j++ ) {
	vScale(i, j) = eta(i, j);

	if (i == j) {
	  vScale(i, j) += thermostat.first;
	}
      }
    }
  }
Beispiel #2
0
Intersect Sphere::intersect(Ray r) {
    Intersect::Intersect ret = *new Intersect::Intersect();
    std::vector<float> d = r.getDir();
    std::vector<float> e = r.getEye();
    std::vector<float> eminusp(3);
    eminusp[0] = e[0] - position[0];
    eminusp[1] = e[1] - position[1];
    eminusp[2] = e[2] - position[2];
    float ddotd = d[0]*d[0]+d[1]*d[1]+d[2]*d[2];
    float empdot = eminusp[0]*eminusp[0] + eminusp[1]*eminusp[1] + eminusp[2]*eminusp[2];
    float ddoteminusp = d[0]*eminusp[0] + d[1]*eminusp[1] + d[2]*eminusp[2];
    float discriminant = sqrt(ddoteminusp * ddoteminusp - ddotd*(empdot - radius*radius));
    if (discriminant >= 0) {
        ret.setHit(true);
        float scalar = -1.0f;
        float * scale = &scalar;
        std::vector<float> scaled(3);
        scaled = vScale(-1, d);
        //scaled[0] = d[0]*(-1);
        //scaled[1] = d[1]*(-1);
        //scaled[2] = d[2]*(-1);
        float sdotemp = scaled[0]*eminusp[0] + scaled[1]*eminusp[1] + scaled[2]*eminusp[2];
        ret.setPoint(r.project((sdotemp+discriminant)/ddotd));
    }
    return ret;
}
void CBodyFX::CreateMarker(LTVector & vPos, LTBOOL bSame)
{
	if (!m_pClientDE || !g_pGameClientShell || !m_hServerObject) return;

	if (!bSame) return;


	ObjectCreateStruct createStruct;
	INIT_OBJECTCREATESTRUCT(createStruct);

	CString str = g_pClientButeMgr->GetSpecialFXAttributeString("TeamSprite");
	LTFLOAT fScaleMult = g_pClientButeMgr->GetSpecialFXAttributeFloat("TeamScale");
	LTFLOAT fAlpha = g_pClientButeMgr->GetSpecialFXAttributeFloat("TeamAlpha");

	LTVector	vScale(1.0f,1.0f,1.0f);

	VEC_MULSCALAR(vScale, vScale, fScaleMult);

	SAFE_STRCPY(createStruct.m_Filename, (char *)(LPCSTR)str);
	createStruct.m_ObjectType	= OT_SPRITE;
	createStruct.m_Flags		= FLAG_VISIBLE | FLAG_FOGDISABLE | FLAG_NOLIGHT;
	createStruct.m_Pos			= vPos;

	m_hMarker = m_pClientDE->CreateObject(&createStruct);
	if (!m_hMarker) return;

	m_pClientDE->SetObjectScale(m_hMarker, &vScale);

    LTFLOAT r, g, b, a;
	m_pClientDE->GetObjectColor(m_hServerObject, &r, &g, &b, &a);

	m_pClientDE->SetObjectColor(m_hObject, r, g, b, (fAlpha * a));

}
Beispiel #4
0
void IMU::orthonormalize(float inputDCM[3][3]) {
    // Takes 700 us.
    // Orthogonalize the i and j unit vectors (DCMDraft2 Eqn. 19).
    errDCM = vDotP(inputDCM[0], inputDCM[1]);
    vScale(inputDCM[1], -errDCM/2, dDCM[0]);   // i vector correction
    vScale(inputDCM[0], -errDCM/2, dDCM[1]);   // j vector correction
    vAdd(inputDCM[0], dDCM[0], inputDCM[0]);
    vAdd(inputDCM[1], dDCM[1], inputDCM[1]);

    // k = i x j
    vCrossP(inputDCM[0], inputDCM[1], inputDCM[2]);

    // Normalize all three vectors.
    vNorm(inputDCM[0]);
    vNorm(inputDCM[1]);
    vNorm(inputDCM[2]);
}
//-- Cube ---------------------------------------------------------------------
//
//-----------------------------------------------------------------------------
void Renderer::Cube( float nx, float ny, float nz, float x, float y, float z )
{
	//    4-------5
	//   /|      /|
	//  0-------1 |
	//  | 7-----|-6
	//  |/      |/
	//  3-------2

	PushMatrix();

	Translate(  ( nx + x ) * 0.5f,
				( ny + y ) * 0.5f,
				( nz + z ) * 0.5f );

	DiffuseUVCubeVertexShader* pShader = NULL;
	if ( g_envMapSet )
	{
		pShader = &DiffuseUVEnvCubeVertexShader::StaticType;
	}
	else
	{
		pShader = &DiffuseUVCubeVertexShader::StaticType;
	}

	CommitTransforms( pShader );
	CommitTextureState();

	PopMatrix();

	D3DXVECTOR4 vScale( ( x - nx ) * 0.5f, ( y - ny ) * 0.5f, ( z - nz ) * 0.5f, 1.0f );

	pShader->SetScale( &vScale );
	pShader->SetColour( &g_fColour );

	m_pD3DDevice->SetVertexShader( pShader->GetVertexShader() );
	m_pD3DDevice->SetVertexDeclaration( g_pPosNormalColUVDeclaration );

	m_pD3DDevice->SetStreamSource( 0,
								   g_pCubeVbuffer,
								   0,
								   sizeof( PosColNormalUVVertex ) );

	m_pD3DDevice->SetIndices( g_pCubeIbuffer );

	m_pD3DDevice->DrawIndexedPrimitive( D3DPT_TRIANGLELIST, 0, 0, 24, 0, 12 );

	m_pD3DDevice->SetStreamSource( 0,
								   NULL,
								   0,
								   sizeof( PosColNormalUVVertex ) );

	m_pD3DDevice->SetIndices( NULL );

} // Cube
Beispiel #6
0
Intersect Triangle::intersect(Ray r) {
	Intersect::Intersect ret = *new Intersect::Intersect();
	float a = v1.getX() - v2.getX();
	float b = v1.getY() - v2.getY();
	float c = v1.getZ() - v2.getZ();
	float d = v1.getX() - v3.getX();
	float e = v1.getY() - v3.getY();
	float f = v1.getZ() - v3.getZ();
	float g = r.getDir().at(0);
	float h = r.getDir().at(1);
	float i = r.getDir().at(2);
	float j = v1.getX() - r.getEye().at(0);
	float k = v1.getY() - r.getEye().at(1);
	float l = v1.getZ() - r.getEye().at(2);
	float eiminushf = e*i - h*f;
	float gfminusdi = g*f - d*i;
	float dhminuseg = d*h - e*g;
	float akminusjb = a*k - j*b;
	float jcminusal = j*c - a*l;
	float blminuskc = b*l - k*c;
	float m = a*(eiminushf) + b*(gfminusdi) + c*(dhminuseg);
	float beta = (j*(eiminushf) + k*(gfminusdi) + l*(dhminuseg))/m;
	if (beta < 0) {return ret;}
	float gamma = (i*(akminusjb) + h*(jcminusal) + g*(blminuskc))/m;
	if (gamma < 0 || beta+gamma > 1) {return ret;}
	float t = (-1)*(f*(akminusjb) + e*(jcminusal) + d*(blminuskc))/m;
	std::vector<float> p;
	
	std::vector<float> vec1 = v1.toVec();
	std::vector<float> vec2 = v2.toVec();
	std::vector<float> vec3 = v3.toVec();
	std::vector<float> sub1 = vSub(&vec2, &vec1);
	std::vector<float> sub2 = vSub(&vec3, &vec1);
	std::vector<float> scaled1 = vScale(&beta, &sub1);
	std::vector<float> scaled2 = vScale(&gamma, &sub2);
	std::vector<float> added1 = vAdd(&vec1, &scaled1);
	p = vAdd(&added1, &scaled2);
	
	ret.setPoint(p);
	
	return ret;
}
void AttachedTorch_cl::InitFunction()
{
  SetVisibleBitmask( 0 );
  SetCastShadows(FALSE);
  m_pShadowCaster = Vision::Game.CreateEntity("VisBaseEntity_cl", GetPosition(), "Data\\Vision\\Samples\\Engine\\Common\\Models\\Warrior\\TorchBottom.MODEL");
  m_pShadowCaster->AttachToParent(this);
  m_pShadowCaster->SetVisibleBitmask( 0 );
  m_pShadowCaster->SetCastShadows( FALSE );
  hkvVec3 vScale(2.5f, 2.5f, 1.0f);
  m_pShadowCaster->SetScaling(vScale);
}
Beispiel #8
0
void SecurityCamera::CreateLight()
{
	// Create the light...and attach it to the camera...

	ObjectCreateStruct theStruct;
	INIT_OBJECTCREATESTRUCT(theStruct);

	theStruct.m_Pos = m_vPos;

	g_pServerButeMgr->GetSecurityCameraString(SCS_GREEN_LIGHT,
		theStruct.m_Filename, ARRAY_LEN(theStruct.m_Filename));

	theStruct.m_Flags = FLAG_VISIBLE; // | FLAG_GLOWSPRITE;
	theStruct.m_Flags2 = FLAG2_ADDITIVE;
	theStruct.m_ObjectType = OT_SPRITE;

    HCLASS hClass = g_pLTServer->GetClass("BaseClass");
    LPBASECLASS pSprite = g_pLTServer->CreateObject(hClass, &theStruct);
	if (!pSprite) return;

	m_hLight = pSprite->m_hObject;

	// Don't eat ticks please...
	::SetNextUpdate(m_hLight, UPDATE_NEVER);

	m_eLightColor = eGreen;

    LTVector vScale(1, 1, 1);
	vScale.x = g_pServerButeMgr->GetSecurityCameraFloat("LightScale");
	vScale.y = vScale.x;

    g_pLTServer->ScaleObject(m_hLight, &vScale);

	// Attach the sprite to the the camera...

    LTVector vOffset(0, 0, 0);
    LTRotation rOffset;

	HATTACHMENT hAttachment;
    LTRESULT dRes = g_pLTServer->CreateAttachment(m_hObject, m_hLight, "Light",
											     &vOffset, &rOffset, &hAttachment);
    if (dRes != LT_OK)
	{
        g_pLTServer->RemoveObject(m_hLight);
        m_hLight = LTNULL;
		return;
	}
}
Beispiel #9
0
HOBJECT CDebrisMgr::CreateDebris(uint8 nDebrisId, const LTVector &vPos, uint8 nNumber)
{
	DEBRIS* pDebris = GetDebris(nDebrisId);
    if (!pDebris) return LTNULL;

	if (pDebris->nNumModels < 1 || !pDebris->szModel[0][0] || nNumber < 1) return LTNULL;

    LTVector vScale(1.0f, 1.0f, 1.0f);
	vScale *= GetRandom(pDebris->fMinScale, pDebris->fMaxScale);

	// Determine the debris model to use, if nNumber is greater than the maximum
	// number of models, wrap around to a valid index
	// 
	int nMaxIndex = pDebris->nNumModels - 1;
	int nIndex = nNumber-1;
	
	while (nIndex > nMaxIndex)
	{
		nIndex -= pDebris->nNumModels;
	}

	char* pFilename = pDebris->szModel[nIndex];

    if (!pFilename) return LTNULL;

	ObjectCreateStruct createStruct;
	INIT_OBJECTCREATESTRUCT(createStruct);

	createStruct.m_ObjectType = OT_MODEL;
	SAFE_STRCPY(createStruct.m_Filename, pFilename);
	createStruct.m_Flags = FLAG_VISIBLE; // | FLAG_NOLIGHT;
	createStruct.m_Pos = vPos;

	pDebris->blrSkinReader.CopyList(0, createStruct.m_SkinNames[0], MAX_CS_FILENAME_LEN+1);
	pDebris->blrRenderStyleReader.CopyList(0, createStruct.m_RenderStyleNames[0], MAX_CS_FILENAME_LEN+1);

    HOBJECT hObj = g_pLTClient->CreateObject(&createStruct);

	//Add code to set alpha!!!!
	//TO DO!!!


    g_pLTClient->SetObjectScale(hObj, &vScale);

	return hObj;
}
void BlMeshBase::LoadMeshNode()
{
	std::string strPath = m_lpThisAB->GetSimulator()->ProjectPath();
	std::string strMeshFile;
	
	if(m_lpThisRB->IsCollisionObject() && m_lpThisMesh->CollisionMeshType() == "CONVEX")
		strMeshFile	= m_lpThisMesh->ConvexMeshFile();
	else
		strMeshFile	= m_lpThisMesh->MeshFile();

	std::string strFile = AnimatSim::GetFilePath(strPath, strMeshFile);
	m_osgBaseMeshNode = GetBlSimulator()->MeshMgr()->LoadMesh(strFile);

	if(!m_osgBaseMeshNode.valid())
		CreateDefaultMesh();

	m_osgBaseMeshNode->setName(m_lpThisAB->Name() + "_MeshNodeBase");

	//Enforce turning on of lighting for this object. Some meshes have this turned off by default (3DS in particular)
	//This did not fix the problem.
	//m_osgBaseMeshNode->getOrCreateStateSet()->setMode( GL_LIGHTING, osg::StateAttribute::OVERRIDE | osg::StateAttribute::ON );

	CStdFPoint vScale(1, 1, 1);

	//If this is a convex collision object then it does not get scaled here. That is done
	//when it is converted into a collision mesh by the editor. Otherwise use the scaling.
	if( !(m_lpThisMesh->IsCollisionObject() && m_lpThisMesh->CollisionMeshType() == "CONVEX") )
		vScale= m_lpThisMesh->Scale();

	osg::Matrix osgScaleMatrix = osg::Matrix::identity();
	osgScaleMatrix.makeScale(vScale.x, vScale.y, vScale.z);

	m_osgMeshNode = new osg::MatrixTransform(osgScaleMatrix);

	m_osgMeshNode->getOrCreateStateSet()->setMode(GL_NORMALIZE, osg::StateAttribute::ON); 

	m_osgMeshNode->addChild(m_osgBaseMeshNode.get());
	m_osgMeshNode->setName(m_lpThisAB->Name() + "_MeshNode");
}
void CProjectileFX::CreateFlare(LTVector & vPos, LTRotation & rRot)
{
	if (!m_pClientDE || !m_hServerObject) return;

	ObjectCreateStruct createStruct;
	createStruct.Clear();

	if (!m_pProjectileFX->szFlareSprite[0]) return;

	SAFE_STRCPY(createStruct.m_Filename, m_pProjectileFX->szFlareSprite);
	createStruct.m_ObjectType = OT_SPRITE;
	createStruct.m_Flags = FLAG_VISIBLE;
	VEC_COPY(createStruct.m_Pos, vPos);
    createStruct.m_Rotation = rRot;

	m_hFlare = m_pClientDE->CreateObject(&createStruct);
	if (!m_hFlare) return;

    LTFLOAT fScale = m_pProjectileFX->fFlareScale;
    LTVector vScale(fScale, fScale, 1.0f);
	m_pClientDE->SetObjectScale(m_hFlare, &vScale);
}
void vHavokShapeFactory::GetHktDependencies(VResourceSnapshot &snapshot, VisStaticMeshInstance_cl *pMeshInstance)
{
  VASSERT(pMeshInstance != NULL);

  // Get scale
  hkvVec3 vScale(hkvNoInitialization);
  ExtractScaling(pMeshInstance->GetTransform(), vScale);

  // There is no real way to figure out if a convex or mesh shape is required and the filename is based on that.
  // So try them both.

  // Convex version
  {
    VStaticString<FS_MAX_PATH> szCachedShapeName(pMeshInstance->GetMesh()->GetFilename());
    bool shrinkToFit = false; //how do if true / can it be true for static mesh?
    vHavokCachedShape::GetConvexShapePath(szCachedShapeName, vScale, shrinkToFit);
    IVFileInStream *pIn = Vision::File.Open(szCachedShapeName);
    if (pIn)
    {
      snapshot.AddFileDependency(pMeshInstance->GetMesh(), szCachedShapeName, pIn->GetSize() );
      pIn->Close();
      return;
    }
  }

  // Mesh version
  {
    VStaticString<FS_MAX_PATH> szCachedShapeName(pMeshInstance->GetMesh()->GetFilename());
    vHavokCachedShape::GetMeshShapePath(szCachedShapeName, vScale, pMeshInstance->GetCollisionBehavior(), pMeshInstance->GetWeldingType());
    IVFileInStream *pIn = Vision::File.Open(szCachedShapeName);
    if (pIn)
    {
      snapshot.AddFileDependency(pMeshInstance->GetMesh(), szCachedShapeName, pIn->GetSize() );
      pIn->Close();
      return;
    }
  }
}
Beispiel #13
0
/*
 * Normalize vector <v_in> (scale it so its length becomes 1) and put the result
 * into <v_out>.
 */
void vNorm(Vector *v_out, Vector *v_in)
{
   double len = vLen(v_in);

   vScale(v_out, v_in, 1 / len);
}
hkRefNew<hkpShape> vHavokShapeFactory::CreateShapeFromStaticMeshInstances(const VisStaticMeshInstCollection &meshInstances, int iCreationFlags, const char **szShapeCacheId)
{
  int iCount = meshInstances.GetLength();
  VVERIFY_OR_RET_VAL(iCount>0 && szShapeCacheId!=NULL, NULL);
  
  // Actual mesh scale, which is only used for caching.
  hkvVec3 vScale(hkvNoInitialization);
  ExtractScaling(meshInstances[0]->GetTransform(), vScale);

  char szShapeId[512];
  const bool bAllowStaticMeshCaching = vHavokPhysicsModule_GetDefaultWorldRuntimeSettings().m_bEnableShapeCaching==TRUE;
  const vHavokPhysicsModule *pModule = vHavokPhysicsModule::GetInstance();
  VASSERT(pModule != NULL);
  const bool bForceHktShapeCaching = pModule->IsHktShapeCachingEnforced();

  // For single mesh instances the per instance welding type is used. For merged mesh instances the global merged welding type is used. 
  VisWeldingType_e eWeldingType = (iCount==1) ? meshInstances[0]->GetWeldingType() : (VisWeldingType_e)vHavokPhysicsModule_GetWorldSetupSettings().m_iMergedStaticWeldingType;

  const bool bAllowPerTriCollisionInfo = iCreationFlags & VShapeCreationFlags_ALLOW_PERTRICOLINFO;
  const bool bShrinkByCvxRadius = iCreationFlags & VShapeCreationFlags_SHRINK;

  // Check whether shape has been already cached for this mesh with the respective scaling.
  // We are just caching single static mesh instances and no static mesh collections.
  hkpShape *pCachedShape = HK_NULL; 
  if (iCount == 1)
  {
    // first, find the convex version
    GetIDStringForConvexShape(szShapeId, meshInstances[0]->GetMesh()->GetFilename(), vScale, bShrinkByCvxRadius);
    pCachedShape = FindShape(szShapeId, szShapeCacheId);
    if (!pCachedShape)
    {
      // then find the mesh version
      GetIDStringForMeshShape(szShapeId, meshInstances[0]->GetMesh()->GetFilename(), vScale, meshInstances[0]->GetCollisionBehavior(), eWeldingType);
      pCachedShape = FindShape(szShapeId, szShapeCacheId);
    }
    if (pCachedShape)
    {
      pCachedShape->addReference();
      return pCachedShape; 
    }

    if (bAllowStaticMeshCaching)
    {
      // first, find the convex version
      pCachedShape = vHavokCachedShape::LoadConvexShape(meshInstances[0]->GetMesh(), vScale, bShrinkByCvxRadius);
      if (pCachedShape)
      {
        *szShapeCacheId = AddShape(szShapeId, pCachedShape);
#ifdef HK_DEBUG_SLOW
        const hkClass* loadedClassType = hkVtableClassRegistry::getInstance().getClassFromVirtualInstance(pCachedShape);
        HK_ASSERT2(0x5432c902, loadedClassType && (hkString::strCmp( loadedClassType->getName(), "hkvConvexVerticesShape" ) == 0), "Serialized in a unexpected cached Havok shape type!");
#endif
        return pCachedShape; 
      }
      else
      {
        // then find the mesh version
        pCachedShape = vHavokCachedShape::LoadMeshShape(meshInstances[0]->GetMesh(), vScale, meshInstances[0]->GetCollisionBehavior(), eWeldingType);
      }
      if (pCachedShape )
      {
        *szShapeCacheId = AddShape(szShapeId, pCachedShape);
#ifdef HK_DEBUG_SLOW
        const hkClass* loadedClassType = hkVtableClassRegistry::getInstance().getClassFromVirtualInstance(pCachedShape);
        HK_ASSERT2(0x5432c902, loadedClassType && (hkString::strCmp( loadedClassType->getName(), "hkvBvCompressedMeshShape" ) == 0), "Serialized in a unexpected cached Havok shape type!");
#endif
        hkvBvCompressedMeshShape *pCompressedMeshShape = reinterpret_cast<hkvBvCompressedMeshShape*>(pCachedShape);
        pCompressedMeshShape->SetupMaterials();
        return pCachedShape; 
      }
      else if(!Vision::Editor.IsInEditor() && !bForceHktShapeCaching)
      {
        Vision::Error.Warning("Cached HKT file for %s is missing. Please generate HKT file (see documentation for details).", meshInstances[0]->GetMesh()->GetFilename());
      }
    }
  }

  // Get the reference transformation. We use the first static mesh as reference
  // transformation, and thus as the position of the corresponding rigid body.
  hkvMat4 referenceTransform = meshInstances[0]->GetTransform();

  // Remove any scaling from the reference matrix. This one has to be applied to
  // the Havok shapes, and thus needs to be part of the mesh transforms.
  referenceTransform.setScalingFactors(hkvVec3 (1));

  // We need the inverse referenceTransform to transform each instance into reference space
  referenceTransform.invert();
  referenceTransform.setRow (3, hkvVec4 (0, 0, 0, 1));

  // Determine collision type from first static mesh instance.
  const VisStaticMeshInstance_cl *pMeshInstance = meshInstances[0];
  VisStaticMesh_cl *pMesh = pMeshInstance->GetMesh();
  IVCollisionMesh *pColMesh = pMesh->GetCollisionMesh(true, true);
  const bool bIsConvex = pColMesh->GetType()==VIS_COLMESH_GEOTYPE_CONVEXHULL;

  // Only create a convex shape if a single mesh instance is used, since otherwise merging multiple mesh instances in one single convex hull
  // will provide in most cases not the desired behavior. Moreover we can only create either a convex hull or a concave mesh shape, therefore
  // mesh instances with different collision type can't be merged into one shape.
  hkpShape *pShape = (bIsConvex && iCount==1) ?
    CreateConvexShapeFromStaticMeshInstances(meshInstances, referenceTransform, bShrinkByCvxRadius) : 
    CreateMeshShapeFromStaticMeshInstances(meshInstances, referenceTransform, bAllowPerTriCollisionInfo, eWeldingType);

  // We are just caching single static mesh instances and no static mesh collections.
  if (iCount == 1)
  {
     *szShapeCacheId = AddShape(szShapeId, pShape);

    // Only cache shape to HKT file when inside vForge or when enforced.
    if ((Vision::Editor.IsInEditor() && bAllowStaticMeshCaching) || bForceHktShapeCaching)
    {
      if (bIsConvex)
        vHavokCachedShape::SaveConvexShape(meshInstances[0]->GetMesh(), vScale, bShrinkByCvxRadius, (hkvConvexVerticesShape*)pShape);
      else
        vHavokCachedShape::SaveMeshShape(meshInstances[0]->GetMesh(), vScale, meshInstances[0]->GetCollisionBehavior(), eWeldingType, (hkvBvCompressedMeshShape*)pShape);
    }
  }
  return pShape;
}
Beispiel #15
0
bool WorldModel::CreateServerMark(CLIENTWEAPONFX & theStruct)
{
	// See if we should create a mark, or simply move one of the GameBase's
	// marks.

	// If the GameBase has the max number of marks or this mark is very close
	// to a pre-existing mark, just move that mark to the new position.

    HOBJECT hMoveObj = LTNULL;
    HOBJECT hFarObj  = LTNULL;

    uint32 nNumMarks = m_MarkList.size( );

    LTFLOAT  fClosestMarkDist  = REGION_DIAMETER;
    LTFLOAT  fFarthestMarkDist = 0.0f;
    uint8   nNumInRegion      = 0;
    LTVector vPos;

	for( ObjRefNotifierList::iterator iter = m_MarkList.begin( ); iter != m_MarkList.end( ); iter++ )
	{
		HOBJECT hObj = *iter;
		if( !hObj )
			continue;

		HATTACHMENT hAttachment = NULL;
        if (LT_OK == g_pLTServer->FindAttachment( m_hObject, hObj, &hAttachment))
		{
			LTransform transform;
            g_pCommonLT->GetAttachmentTransform(hAttachment, transform, LTTRUE);

			vPos = transform.m_Pos;
		}

        LTFLOAT fDist = VEC_DISTSQR(vPos, theStruct.vPos);
		if (fDist < REGION_DIAMETER)
		{
			if (fDist < fClosestMarkDist)
			{
				fClosestMarkDist = fDist;
				hMoveObj = hObj;
			}

			if (++nNumInRegion > MAX_MARKS_IN_REGION)
			{
				// Just move this mark to the correct pos...
				hMoveObj = hMoveObj ? hMoveObj : hObj;
				break;
			}
		}

		if (fDist > fFarthestMarkDist)
		{
			fFarthestMarkDist = fDist;
			hFarObj = hObj;
		}
	}

	// If we've got the max number of marks on this object, just move
	// the closest one to the new position...

	if (nNumMarks >= MAX_MARKS_PER_OBJECT)
	{
		if( !hMoveObj )
		{
			if( hFarObj )
			{
				hMoveObj = hFarObj;
			}
			else
			{
				HOBJECT hFirstMark = *m_MarkList.begin( );
				hMoveObj = hFirstMark;
			}
		}
	}
	else
	{
        hMoveObj = LTNULL; // Need to create one...
	}

	// Re-setup the object to move it...

	if (hMoveObj && IsKindOf(hMoveObj, "CServerMark"))
	{
        CServerMark* pMoveMark = (CServerMark*) g_pLTServer->HandleToObject(hMoveObj);
		if (!pMoveMark)
			return false;

		// Since this mark is already attached to us, remove the attachment
		DetachObject( pMoveMark->m_hObject );

		if( !AttachServerMark( *pMoveMark, (CLIENTWEAPONFX)theStruct))
		{
			g_pLTServer->RemoveObject( pMoveMark->m_hObject );
			RemoveMarkFromList( pMoveMark->m_hObject );
			pMoveMark = NULL;
			return false;
		}

		return true;
	}


	// Okay, no luck, need to create a new mark...

	ObjectCreateStruct createStruct;
	INIT_OBJECTCREATESTRUCT(createStruct);

    LTFLOAT fScaleAdjust = 1.0f;
	if (!GetImpactSprite((SurfaceType)theStruct.nSurfaceType, fScaleAdjust,
		theStruct.nAmmoId, createStruct.m_Filename, ARRAY_LEN(createStruct.m_Filename)))
	{
		return false;
	}

	createStruct.m_ObjectType = OT_SPRITE;
	createStruct.m_Flags = FLAG_VISIBLE | FLAG_NOLIGHT | FLAG_ROTATEABLESPRITE;
	createStruct.m_Pos = theStruct.vPos;

	createStruct.m_Rotation = LTRotation(theStruct.vSurfaceNormal, LTVector(0.0f, 1.0f, 0.0f));

	AMMO const *pAmmo = g_pWeaponMgr->GetAmmo(theStruct.nAmmoId);
	if( !pAmmo ) 
		return false;

    static HCLASS hClass = g_pLTServer->GetClass("CServerMark");
    CServerMark* pMark = (CServerMark*) g_pLTServer->CreateObject(hClass, &createStruct);
	if (!pMark)
		return false;


	// Randomly adjust the mark's scale to add a bit o spice...

	if (pAmmo->pImpactFX)
	{
        LTFLOAT fScale = fScaleAdjust * pAmmo->pImpactFX->fMarkScale;

        LTVector vScale(fScale, fScale, fScale);
        g_pLTServer->ScaleObject(pMark->m_hObject, &vScale);
	}

	if( !AttachServerMark( *pMark, (CLIENTWEAPONFX)theStruct))
	{
		g_pLTServer->RemoveObject( pMark->m_hObject );
		pMark = NULL;
		return false;
	}

	AddMarkToList( pMark->m_hObject );

	return true;
}
void VCoronaManager::RenderCorona (VCoronaCandidate& coronaCandidate, VTextureObject*& pTexture)
{
#ifdef SUPPORTS_CORONAS
  VCoronaComponent *pCorona = coronaCandidate.m_pCorona;
  VisRenderContext_cl* pContext = VisRenderContext_cl::GetCurrentContext();
  VisLightSource_cl* pLight = (VisLightSource_cl*)pCorona->GetOwner();

  hkvVec3 vLightPos(hkvNoInitialization);
  pLight->GetVirtualPosition(vLightPos, pContext);
  hkvVec3 vEyePos(hkvNoInitialization);
  pContext->GetCamera()->GetPosition(vEyePos);
  hkvVec3 vDir = pContext->GetCamera()->GetDirection();

  // Corona texture
  VTextureObject *pTex = pCorona->GetCoronaTexture();
  if (pTex == NULL)
    return;

  if (pTexture != pTex)
  {
    pTexture = pTex;
    Vision::RenderLoopHelper.BindMeshTexture(pTexture,0);
  }

  // Get light color
  VColorRef color = pLight->GetColor();
  hkvVec3 vDist = vLightPos - vEyePos;
  float fEyeDist = vDir.dot(vDist);

  //determine if camera is in light cone if the light is directional
  float fDirectionalDampening = 1.0f;
  if ( pLight->GetType() == VIS_LIGHT_SPOTLIGHT && pCorona->GetOnlyVisibleInSpotLight() )
  {
    fDirectionalDampening = 0.0f;
    float fConeAngle = pLight->GetProjectionAngle();
    float fConeLength = pLight->GetRadius();
    hkvVec3 fConeDirection = pLight->GetDirection();
    fConeDirection.normalize();

    hkvVec3 vLightEyeDist = vEyePos - vLightPos;

    //#2 check if the camera is inside the angle of the cone
    float cosinusAngle = (vLightEyeDist/vLightEyeDist.getLength()).dot(fConeDirection);
    float fDegree = hkvMath::acosDeg(cosinusAngle);
    float normRadius = fDegree / (fConeAngle/2.0f);

    if (normRadius < 1.0f)
    {
      //hardcoded falloff. For better performance, we avoid sampling the projection texture here.
      const float fEpsilon = 64.0f/256.0f;
      const float fQuadFactor = 1.0f/fEpsilon - 1.0f;
      fDirectionalDampening = 1.0f / (1.0f + fQuadFactor*normRadius*normRadius);

      // scale the function so that the value is exactly 0.0 at the edge and 1.0 in the center
      fDirectionalDampening = (fDirectionalDampening - fEpsilon) / (1.0f - fEpsilon);  
    }
  }
  // Fog params
  float fFogDampening = 1.0f;
  if (pLight->GetType() != VIS_LIGHT_DIRECTED && Vision::World.IsLinearDepthFogEnabled())
  {  
    const VFogParameters &fog = Vision::World.GetFogParameters();
    float fFogStart = fog.fDepthStart;
    float fFogEnd = fog.fDepthEnd;

    float fFogFactor = (fFogEnd > fFogStart) ? ((fEyeDist - fFogStart) / (fFogEnd - fFogStart)) : 0.f;
    fFogDampening = 1.0f - hkvMath::clamp(fFogFactor, 0.0f, 1.0f);
  }

  // Get corona rotation
  float fRotation = 0.0f;
  hkvVec4 vRotation(1.0f, 0.0f, 0.0f, 1.0f);
  if (pCorona->CoronaFlags & VIS_CORONASCALE_ROTATING)
  { 
    fRotation = hkvMath::mod (fEyeDist * 0.5f, 360.f);

    vRotation.x = hkvMath::cosDeg (fRotation);
    vRotation.y = -hkvMath::sinDeg (fRotation);
    vRotation.z = -vRotation.y;
    vRotation.w = vRotation.x;
  }

  // Texture dimensions
  int iSizeX, iSizeY, depth;
  pTex->GetTextureDimensions(iSizeX, iSizeY, depth);

  hkvVec4 vScale(0.0f, 0.0f, 0.0f, 0.0f);

  int iMainWidth, iMainHeight, iWidth, iHeight;
  pContext->GetSize(iWidth, iHeight);
  VisRenderContext_cl::GetMainRenderContext()->GetSize(iMainWidth, iMainHeight);

  // Preserve texture aspect ratio
  int iTexHeight = pTex->GetTextureHeight();
  int iTexWidth = pTex->GetTextureWidth();

  // Perspective scaling
  // This scaling ensures roughly the same size on 720p as the old implementation.
  vScale.z = iTexWidth * pCorona->CoronaScaling * 0.25f;
  vScale.w = iTexHeight * pCorona->CoronaScaling * 0.25f;

  // Screen-space scaling
  // This scaling ensures roughly the same size on 720p as the old implementation.
  const float fScaleFactor = pCorona->CoronaScaling * iMainHeight / 11.0f;
  vScale.x = ((float)iTexWidth / 128.0f) * fScaleFactor * (float(iWidth) / float(iMainWidth));
  vScale.y = ((float)iTexHeight / 128.0f) * fScaleFactor * (float(iHeight) / float(iMainHeight));
  vScale.x *= 2.0f / iWidth;
  vScale.y *= 2.0f / iHeight;
  
  // Scale by visibility
  if (pCorona->CoronaFlags & VIS_CORONASCALE_VISIBLEAREA)
  {
    vScale.x *= coronaCandidate.m_fCurrentVisibility;
    vScale.y *= coronaCandidate.m_fCurrentVisibility;
    vScale.z *= coronaCandidate.m_fCurrentVisibility;
    vScale.w *= coronaCandidate.m_fCurrentVisibility;
  }

  VCompiledShaderPass* pShader = m_spCoronaTechnique->GetShader(0);
  VShaderConstantBuffer *pVertexConstBuffer = pShader->GetConstantBuffer(VSS_VertexShader);
  // xyz = worldspace position, w = 1.0 if VIS_CORONASCALE_DISTANCE is true, otherwise zero.
  pVertexConstBuffer->SetSingleParameterF("coronaPosition", vLightPos.x, vLightPos.y, vLightPos.z, (pCorona->CoronaFlags & VIS_CORONASCALE_DISTANCE) ? 1.0f : 0.0f);
  // xyz = light color, w = corona visibility.
  pVertexConstBuffer->SetSingleParameterF("coronaColor", color.r/255.0f, color.g/255.0f, color.b/255.0f, coronaCandidate.m_fCurrentVisibility * fFogDampening * fDirectionalDampening);
  // xyzw = 2x2 rotation matrix. float2x2 is not supported in shader model 2, so a float4 is used and multiplication is done manually in the shader.
  pVertexConstBuffer->SetSingleParameterF("coronaRotation", vRotation.x, vRotation.y, vRotation.z, vRotation.w);
  // xy = screen-space scaling. zw = view-space scaling.
  pVertexConstBuffer->SetSingleParameterF("coronaScale", vScale.x, vScale.y, vScale.z, vScale.w);
    
  Vision::RenderLoopHelper.RenderMeshes(pShader, VisMeshBuffer_cl::MB_PRIMTYPE_TRILIST, 0, 2, 6);
#endif
}
Beispiel #17
0
bool CLTBBouncyChunkFX::Update(float tmFrameTime)
{
	// Base class update first
	
	if (!CBaseFX::Update(tmFrameTime)) 
		return false;

	if ((m_hImpactSound) && (m_pLTClient->IsDone(m_hImpactSound)))
	{
		m_pLTClient->SoundMgr()->KillSound(m_hImpactSound);
		m_hImpactSound = NULL;
	}

	// Set the object scale

	LTVector vScale(m_scale, m_scale, m_scale);

	m_pLTClient->SetObjectScale(m_hBouncyChunk, &vScale);

	LTVector vCur;
	m_pLTClient->GetObjectPos(m_hBouncyChunk, &vCur);
		
	// Compute the new position of the chunk

	LTVector vNew = vCur;
	vNew += m_vVel * tmFrameTime;
	
	m_vVel += GetProps()->m_vGravity * tmFrameTime;
	
	// Move the object and collide against the world

	ClientIntersectQuery ciq;
	ClientIntersectInfo  cii;

	ciq.m_From  = vCur;
	ciq.m_To    = vNew;

	if (m_pLTClient->IntersectSegment(&ciq, &cii))
	{
		vNew = cii.m_Point + cii.m_Plane.m_Normal;
		vCur = vNew;

		// Compute the reflected velocity

		LTVector N = cii.m_Plane.m_Normal;
		LTVector L = m_vVel;
		L.x = -L.x;
		L.y = -L.y;
		L.z = -L.z;
		
		LTVector vReflected = N * 2.0f;
		vReflected *= (N.Dot(L));
		vReflected -= L;

		vReflected.Norm();
		vReflected *= (m_vVel.Mag() * 0.7f);

		m_vVel = vReflected;

		const char *sImpactSound = GetProps()->m_sImpactSound;
		if (sImpactSound[0] != '.')
		{
			// Play the bounce sound

			PlaySoundInfo psi;
			memset(&psi, 0, sizeof(PlaySoundInfo));

			psi.m_dwFlags = PLAYSOUND_GETHANDLE |
							PLAYSOUND_CTRL_VOL |
							PLAYSOUND_CLIENT |
							PLAYSOUND_TIME |
							PLAYSOUND_3D | 
							PLAYSOUND_REVERB;

			psi.m_nVolume = 50;

			strcpy(psi.m_szSoundName, GetProps()->m_sImpactSound);
			psi.m_nPriority		= 0;
			psi.m_vPosition		= m_vPos;
			psi.m_fInnerRadius	= 100;
			psi.m_fOuterRadius	= 300;

			if (!m_hImpactSound)
			{
				if (m_pLTClient->SoundMgr()->PlaySound(&psi, m_hImpactSound) == LT_OK)
				{
					m_hImpactSound = psi.m_hSound;
				}
			}
		}
	}

	m_pLTClient->SetObjectPos(m_hBouncyChunk, &vNew);
	m_pLTClient->SetObjectColor(m_hBouncyChunk, m_red, m_green, m_blue, m_alpha);
	m_pLTClient->SetObjectPos(m_hObject, &vNew);

	// Success !!

	return true;
}
Beispiel #18
0
vec2 symmetricUnitBall() {
    return vScale(rfloat(), uniformUnitCirc());
}
Beispiel #19
0
void		GGbsModel::MultiAniFrame(){

	D3DXMATRIX matWldTrans;
	D3DXMATRIX matWldRotate;
	D3DXMATRIX matWldScale;
	D3DXMatrixIdentity(&matWldTrans);
	D3DXMatrixIdentity(&matWldRotate);
	D3DXMatrixIdentity(&matWldScale);
	

	D3DXQUATERNION qR, qS;

	D3DXMATRIX matCalc;
	D3DXMatrixIdentity(&matCalc);


	//m_fTickFrame = 6400.0f;
	m_fTickFrame += g_fSecPerFrame * m_fFrameSpeed *m_fTickPerFrame;
	if (m_fTickFrame >= m_fLastFrame * m_fTickPerFrame /*마지막 프레임 틱수*/)
	{
		m_fTickFrame = 0.0f;
	}

	//m_fTickFrame += 1000.0f;
	//if (m_fTickFrame >= 8000.0f /*마지막 프레임 틱수*/)
	//{
	//	m_fTickFrame = 0.0f;
	//}

	for (int i = 0; i < m_vGeomObj.size() ; i++) {

		if (m_vGeomObj[i]->m_bUsed == false)
			continue;

		D3DXMatrixIdentity(&m_vGeomObj[i]->m_matCalculation);

		matWldRotate = m_vGeomObj[i]->m_matWldRotate;
		matWldTrans = m_vGeomObj[i]->m_matWldTrans;
		matWldScale = m_vGeomObj[i]->m_matWldScale;

		D3DXQuaternionRotationMatrix(&qR, &matWldRotate);
		D3DXQuaternionRotationMatrix(&qS, &matWldScale);
		//for (int j = 0; j < m_vGeomObj[i]->m_vObj.size(); j++) {

			//if (m_vGeomObj[i].get()->m_bHasAniTrack) {






		//Translation
		if (m_vGeomObj[i].get()->m_vPosTrack.size() != 0) {

			GAnimTrack* pStartTrack = NULL;
			GAnimTrack* pEndTrack = NULL;

			//현재 Tick이 어디인지 찾자.
			GetAnimationTrack(m_fTickFrame, &pStartTrack, &pEndTrack, ANITRACK_TYPE_POS, i);

			//애니메이션 보간.
			D3DXVECTOR3 vResultVector;
			D3DXVECTOR3 vP1 = pStartTrack->vecVector;
			D3DXVECTOR3 vP2 = pEndTrack->vecVector;

			float fTValue = (m_fTickFrame - pStartTrack->iTick) / (pEndTrack->iTick - pStartTrack->iTick);

			if(pStartTrack != pEndTrack){
				D3DXVec3Lerp(&vResultVector, &vP1, &vP2, fTValue);

				//T행렬 값 대입
				matWldTrans._41 = vResultVector.x;
				matWldTrans._42 = vResultVector.y;
				matWldTrans._43 = vResultVector.z;
			}
			else {
				//T행렬 값 대입
				matWldTrans._41 = pStartTrack->vecVector.x;
				matWldTrans._42 = pStartTrack->vecVector.y;
				matWldTrans._43 = pStartTrack->vecVector.z;
			}
		}

		//Rotation
		if (m_vGeomObj[i].get()->m_vRotTrack.size() != 0) {
			GAnimTrack* pStartTrack = NULL;
			GAnimTrack* pEndTrack = NULL;
			//D3DXQUATERNION qR;

			//현재 Tick이 어디인지 찾자.
			GetAnimationTrack(m_fTickFrame, &pStartTrack, &pEndTrack, ANITRACK_TYPE_ROT, i);


			//사원수간의 보간..
			if (pStartTrack == NULL && pEndTrack == NULL) {
				qR = m_vGeomObj[i].get()->m_vRotTrack[0]->qRotate;// = m_vGeomObj[i].get()->m_qRotation;
			}
			else if (pStartTrack == NULL) {
				qR;// = m_vGeomObj[i].get()->m_qRotation;
				float fTValue = (m_fTickFrame - 0) / (pEndTrack->iTick - 0);
				D3DXQuaternionSlerp(&qR, &qR, &pEndTrack->qRotate, fTValue);
			}
			else if (pEndTrack == NULL) {
				qR = m_vGeomObj[i].get()->m_vRotTrack[m_vGeomObj[i].get()->m_vRotTrack.size() - 1].get()->qRotate;
				float fTValue = ((m_fTickFrame - pStartTrack->iTick) / (m_fFrameSpeed*m_fTickPerFrame));
				D3DXQuaternionSlerp(&qR, &qR, &qR, fTValue);
			}
			else {
				qR = pStartTrack->qRotate;
				float fTValue = (m_fTickFrame - pStartTrack->iTick) / (pEndTrack->iTick - pStartTrack->iTick);
				D3DXQuaternionSlerp(&qR, &qR, &pEndTrack->qRotate, fTValue);
			}

			//사원수에서 행렬로 변환.
			D3DXMatrixRotationQuaternion(&matWldRotate, &qR);// 사원수에서 행렬로 변환
		}

		//Scale
		if (m_vGeomObj[i].get()->m_vSclTrack.size() != 0) {

			GAnimTrack* pStartTrack = NULL;
			GAnimTrack* pEndTrack = NULL;

			D3DXMATRIX matScaleRot, matInvScaleRot;
			D3DXMatrixIdentity(&matScaleRot);
			D3DXMatrixIdentity(&matInvScaleRot);

			//D3DXQUATERNION qS;
			float fStartTick = 0.0f, fEndTick = 0.0f;
			D3DXVECTOR3 vScale(m_vGeomObj[i].get()->m_matWldScale._11, m_vGeomObj[i].get()->m_matWldScale._22, m_vGeomObj[i].get()->m_matWldScale._33);

			//현재 Tick이 어디인지 찾자.
			GetAnimationTrack(m_fTickFrame, &pStartTrack, &pEndTrack, ANITRACK_TYPE_SCL, i);

			//신축트랙 보간
			if (pStartTrack == NULL) {
				//vScale = m_vGeomObj[i].get()->m_vecTM_SCALE;

				//D3DXQuaternionRotationAxis(&qS, &m_vGeomObj[i].get()->m_vecTM_SCALE_AXIS, m_vGeomObj[i].get()->m_fTM_SCALEAXISANG);

				fStartTick = 0.0f;
				fEndTick = pEndTrack->iTick;
			}
			else if (pEndTrack == NULL) {
				vScale = pStartTrack->vecVector;
				qS = pStartTrack->qRotate;

				fStartTick = pStartTrack->iTick;

				fEndTick = pStartTrack->iTick + (m_fFrameSpeed*m_fTickPerFrame);
			}
			else {
				vScale = pStartTrack->vecVector;
				qS = pStartTrack->qRotate;

				fStartTick = pStartTrack->iTick;
				fEndTick = pEndTrack->iTick;


			}
			float fTValue = (m_fTickFrame - fStartTick) / (fEndTick - fStartTick);

			D3DXVec3Lerp(&vScale, &vScale, &pEndTrack->vecVector, fTValue);
			D3DXQuaternionSlerp(&qS, &qS, &pEndTrack->qRotate, fTValue);

			//사원수 -> 행렬로 변환등...
			D3DXMatrixScaling(&matWldScale, vScale.x, vScale.y, vScale.z);
			D3DXMatrixRotationQuaternion(&matScaleRot, &qS);
			D3DXMatrixInverse(&matInvScaleRot, NULL, &matScaleRot);

			matWldScale = matInvScaleRot * matWldScale * matScaleRot;



		}

		if (m_vGeomObj[i].get()->m_pParentObj != NULL) {

			m_vGeomObj[i].get()->m_matCalculation  = matCalc = matWldScale * matWldRotate * matWldTrans
				* m_vGeomObj[i].get()->m_pParentObj->m_matCalculation;
			int iTest = 0;

			// 인버스 매트릭스 확인 코드.
			D3DXVECTOR3 v0, v1, v2, v3;
			v0 = m_vGeomObj[i].get()->m_matCalculation.m[0];
			v1 = m_vGeomObj[i].get()->m_matCalculation.m[1];
			v2 = m_vGeomObj[i].get()->m_matCalculation.m[2];
			D3DXVec3Cross(&v3, &v1, &v2);
			if (D3DXVec3Dot(&v3, &v0) < 0.0f)
			{
				D3DXMATRIX matW;
				D3DXMatrixScaling(&matW, -1.0f, -1.0f, -1.0f);
				D3DXMatrixMultiply(&m_vGeomObj[i].get()->m_matCalculation,
					&m_vGeomObj[i].get()->m_matCalculation, &matW);
			}
		}
		else {
			m_vGeomObj[i].get()->m_matCalculation = matCalc = matWldScale * matWldRotate * matWldTrans;
			int iTest = 0;

			// 인버스 매트릭스 확인 코드.
			D3DXVECTOR3 v0, v1, v2, v3;
			v0 = m_vGeomObj[i].get()->m_matCalculation.m[0];
			v1 = m_vGeomObj[i].get()->m_matCalculation.m[1];
			v2 = m_vGeomObj[i].get()->m_matCalculation.m[2];
			D3DXVec3Cross(&v3, &v1, &v2);
			if (D3DXVec3Dot(&v3, &v0) < 0.0f)
			{
				D3DXMATRIX matW;
				D3DXMatrixScaling(&matW, -1.0f, -1.0f, -1.0f);
				D3DXMatrixMultiply(&m_vGeomObj[i].get()->m_matCalculation,
					&m_vGeomObj[i].get()->m_matCalculation, &matW);
			}
		}
	}
			//}
			
		//}

		//최종행렬.


	
}
Beispiel #20
0
D3DXMATRIX GAnimation::Interpolate(GMesh* pMesh, D3DXMATRIX* matParents, float fFrameTick, TScene tScene)
{

	// TM		= AnimMat * ParentTM;
	// AaniMat	= TM * Inverse(ParentTM)
	D3DXQUATERNION qR, qS;
	D3DXMATRIX matAnim, matPos, matRotate, matScale, matCalculation;

	D3DXMatrixIdentity(&matCalculation);

	matRotate = pMesh->m_matWorldRotate;
	matPos = pMesh->m_matWorldTrans;
	matScale = pMesh->m_matWorldScale;

	D3DXQuaternionRotationMatrix(&qR, &matRotate);
	D3DXQuaternionRotationMatrix(&qS, &matScale);

	// fFrameTick = m_Scene.iFirstFrame * m_Scene.iTickPerFrame + CurFame;
	float fStartTick = tScene.iFirstFrame * tScene.iTickPerFrame;
	float fEndTick = 0.0f;

	TAnimTrack* pStartTrack = NULL;
	TAnimTrack* pEndTrack = NULL;
	if (pMesh->m_pRotTrack.size())
	{
		// pStartTrack를 찾을수 있으면
		if (GetAnimationTrack(fFrameTick, pMesh->m_pRotTrack, &pStartTrack, &pEndTrack))
		{
			qR = pStartTrack->qRotate;
			fStartTick = pStartTrack->iTick;
		}
		if (pEndTrack)
		{
			fEndTick = pEndTrack->iTick;
			D3DXQuaternionSlerp(&qR, &qR, &pEndTrack->qRotate, (fFrameTick - fStartTick) / (fEndTick - fStartTick));
		}
		D3DXMatrixRotationQuaternion(&matRotate, &qR);
	}

	pStartTrack = NULL;
	pEndTrack = NULL;

	D3DXVECTOR3 Trans(matPos._41, matPos._42, matPos._43);
	if (pMesh->m_pPosTrack.size())
	{
		// pStartTrack를 찾을수 있으면
		if (GetAnimationTrack(fFrameTick, pMesh->m_pPosTrack, &pStartTrack, &pEndTrack))
		{
			Trans = pStartTrack->vVector;
			fStartTick = pStartTrack->iTick;
		}
		if (pEndTrack)
		{
			fEndTick = pEndTrack->iTick;
			D3DXVec3Lerp(&Trans, &Trans, &pEndTrack->vVector, (fFrameTick - fStartTick) / (fEndTick - fStartTick));
		}

		D3DXMatrixTranslation(&matPos, Trans.x, Trans.y, Trans.z);
	}


	pStartTrack = NULL;
	pEndTrack = NULL;

	D3DXMATRIX matScaleRot, matInvScaleRot;
	D3DXVECTOR3 vScale(matScale._11, matScale._22, matScale._33);
	if (pMesh->m_pSclTrack.size())
	{
		// pStartTrack를 찾을수 있으면
		if (GetAnimationTrack(fFrameTick, pMesh->m_pSclTrack, &pStartTrack, &pEndTrack))
		{
			vScale = pStartTrack->vVector;
			qS = pStartTrack->qRotate;
			fStartTick = pStartTrack->iTick;
		}
		if (pEndTrack)
		{
			fEndTick = pEndTrack->iTick;
			D3DXVec3Lerp(&vScale, &vScale, &pEndTrack->vVector, (fFrameTick - fStartTick) / (fEndTick - fStartTick));
			D3DXQuaternionSlerp(&qS, &qS, &pEndTrack->qRotate, (fFrameTick - fStartTick) / (fEndTick - fStartTick));
		}
		D3DXMatrixScaling(&matScale, vScale.x, vScale.y, vScale.z);
		D3DXMatrixRotationQuaternion(&matScaleRot, &qS);
		D3DXMatrixInverse(&matInvScaleRot, NULL, &matScaleRot);
		matScale = matInvScaleRot  * matScale * matScaleRot;
	}

	pStartTrack = NULL;
	pEndTrack = NULL;

	float fCurAlpha, fNextAlpha, fOffSet;
	fCurAlpha = 0.0f;
	fNextAlpha = 0.0f;
	if (pMesh->m_pVisTrack.size())
	{
		// pStartTrack를 찾을수 있으면
		if (GetAnimationTrack(fFrameTick, pMesh->m_pVisTrack, &pStartTrack, &pEndTrack))
		{
			fCurAlpha = pStartTrack->vVector.x;
			fStartTick = pStartTrack->iTick;
		}
		if (pEndTrack)
		{
			fNextAlpha = pEndTrack->vVector.x;
			fEndTick = pEndTrack->iTick;

			fOffSet = (fFrameTick - fStartTick) / (fEndTick - fStartTick);
			fNextAlpha = (fNextAlpha - fCurAlpha)*fOffSet;
		}
		pMesh->m_fVisibility = (fCurAlpha + fNextAlpha);
	}
	else
	{
		pMesh->m_fVisibility = 1.0f;
	}

	D3DXMatrixMultiply(&matAnim, &matScale, &matRotate);
	matAnim._41 = matPos._41;
	matAnim._42 = matPos._42;
	matAnim._43 = matPos._43;
	// 최종 에미메이션 행렬을 완성한다.	
	D3DXMatrixMultiply(&matCalculation, &matAnim, matParents);

	// 인버스 매트릭스 확인 코드.
	D3DXVECTOR3 v0, v1, v2, v3;
	v0 = pMesh->m_matCalculation.m[0];
	v1 = pMesh->m_matCalculation.m[1];
	v2 = pMesh->m_matCalculation.m[2];
	D3DXVec3Cross(&v3, &v1, &v2);
	if (D3DXVec3Dot(&v3, &v0) < 0.0f)
	{
		D3DXMATRIX matW;
		D3DXMatrixScaling(&matW, -1.0f, -1.0f, -1.0f);
		D3DXMatrixMultiply(&matCalculation, &pMesh->m_matCalculation, &matW);
	}
	return matCalculation;
}
Beispiel #21
0
void		GGbsModel::SingleAniFrame() {

	D3DXMATRIX matWldTrans;
	D3DXMATRIX matWldRotate;
	D3DXMATRIX matWldScale;
	D3DXMatrixIdentity(&matWldTrans);
	D3DXMatrixIdentity(&matWldRotate);
	D3DXMatrixIdentity(&matWldScale);

	m_fTickFrame += g_fSecPerFrame * m_fFrameSpeed *m_fTickPerFrame;
	if (m_fTickFrame >= m_fLastFrame * m_fTickPerFrame /*마지막 프레임 틱수*/)
	{
		m_fTickFrame = 0.0f;
	}


	if (m_vGeomObj[0].get()->m_bHasAniTrack) {

		//Translation
		if (m_vGeomObj[0].get()->m_vPosTrack.size() != 0) {

			GAnimTrack* pStartTrack = NULL;
			GAnimTrack* pEndTrack = NULL;

			//현재 Tick이 어디인지 찾자.
			GetAnimationTrack(m_fTickFrame, &pStartTrack, &pEndTrack, ANITRACK_TYPE_POS);

			//애니메이션 보간.
			D3DXVECTOR3 vResultVector;
			D3DXVECTOR3 vP1 = pStartTrack->vecVector;
			D3DXVECTOR3 vP2 = pEndTrack->vecVector;

			float fTValue = (m_fTickFrame - pStartTrack->iTick) / (pEndTrack->iTick - pStartTrack->iTick);

			D3DXVec3Lerp(&vResultVector, &vP1, &vP2, fTValue);

			//T행렬 값 대입
			matWldTrans._41 = vResultVector.x;
			matWldTrans._42 = vResultVector.y;
			matWldTrans._43 = vResultVector.z;
		}

		//Rotation
		if (m_vGeomObj[0].get()->m_vRotTrack.size() != 0) {
			GAnimTrack* pStartTrack = NULL;
			GAnimTrack* pEndTrack = NULL;
			D3DXQUATERNION qR;

			//현재 Tick이 어디인지 찾자.
			GetAnimationTrack(m_fTickFrame, &pStartTrack, &pEndTrack, ANITRACK_TYPE_ROT);


			//사원수간의 보간..
			if (pStartTrack == NULL) {
				qR = m_vGeomObj[0].get()->m_qRotation;
				float fTValue = (m_fTickFrame - 0) / (pEndTrack->iTick - 0);
				D3DXQuaternionSlerp(&qR, &qR, &pEndTrack->qRotate, fTValue);
			}
			else if (pEndTrack == NULL) {
				qR = m_vGeomObj[0].get()->m_vRotTrack[m_vGeomObj[0].get()->m_vRotTrack.size() - 1].get()->qRotate;
				float fTValue = ((m_fTickFrame - pStartTrack->iTick) / (m_fFrameSpeed*m_fTickPerFrame));
				D3DXQuaternionSlerp(&qR, &qR, &qR, fTValue);
			}
			else {
				qR = pStartTrack->qRotate;
				float fTValue = (m_fTickFrame - pStartTrack->iTick) / (pEndTrack->iTick - pStartTrack->iTick);
				D3DXQuaternionSlerp(&qR, &qR, &pEndTrack->qRotate, fTValue);
			}

			//사원수에서 행렬로 변환.
			D3DXMatrixRotationQuaternion(&matWldRotate, &qR);// 사원수에서 행렬로 변환
		}

		//Scale
		if (m_vGeomObj[0].get()->m_vSclTrack.size() != 0) {

			GAnimTrack* pStartTrack = NULL;
			GAnimTrack* pEndTrack = NULL;

			D3DXMATRIX matScaleRot, matInvScaleRot;
			D3DXMatrixIdentity(&matScaleRot);
			D3DXMatrixIdentity(&matInvScaleRot);

			D3DXQUATERNION qS;
			float fStartTick = 0.0f, fEndTick = 0.0f;
			D3DXVECTOR3 vScale(m_vGeomObj[0].get()->m_matWldScale._11, m_vGeomObj[0].get()->m_matWldScale._22, m_vGeomObj[0].get()->m_matWldScale._33);

			//현재 Tick이 어디인지 찾자.
			GetAnimationTrack(m_fTickFrame, &pStartTrack, &pEndTrack, ANITRACK_TYPE_SCL);

			//신축트랙 보간
			if (pStartTrack == NULL) {
				//vScale = m_vGeomObj[0].get()->m_vecTM_SCALE;

				D3DXQuaternionRotationAxis(&qS, &m_vGeomObj[0].get()->m_vecTM_SCALE_AXIS, m_vGeomObj[0].get()->m_fTM_SCALEAXISANG);

				fStartTick = 0.0f;
				fEndTick = pEndTrack->iTick;
			}
			else if (pEndTrack == NULL) {
				vScale = pStartTrack->vecVector;
				qS = pStartTrack->qRotate;

				fStartTick = pStartTrack->iTick;

				fEndTick = pStartTrack->iTick + (m_fFrameSpeed*m_fTickPerFrame);
			}
			else {
				vScale = pStartTrack->vecVector;
				qS = pStartTrack->qRotate;

				fStartTick = pStartTrack->iTick;
				fEndTick = pEndTrack->iTick;


			}
			float fTValue = (m_fTickFrame - fStartTick) / (fEndTick - fStartTick);

			D3DXVec3Lerp(&vScale, &vScale, &pEndTrack->vecVector, fTValue);
			D3DXQuaternionSlerp(&qS, &qS, &pEndTrack->qRotate, fTValue);

			//사원수 -> 행렬로 변환등...
			D3DXMatrixScaling(&matWldScale, vScale.x, vScale.y, vScale.z);
			D3DXMatrixRotationQuaternion(&matScaleRot, &qS);
			D3DXMatrixInverse(&matInvScaleRot, NULL, &matScaleRot);

			matWldScale = matInvScaleRot * matWldScale * matScaleRot;



		}

		m_vGeomObj[0].get()->m_matCalculation = matWldScale
												* matWldRotate
												* matWldTrans;
	}
}
Beispiel #22
0
LTBOOL   CFolderPlayer::CreatePlayerModel(LTBOOL bNewSkin /* = LTTRUE */)
{
	HOBJECT hCamera = g_pGameClientShell->GetInterfaceCamera();
    if (!hCamera) return LTFALSE;

	if (!strlen(m_szPlayerModel)) return LTFALSE;
	char temp[128];
	strcpy(temp,m_szPlayerModel);
	char *pTemp = strtok(temp,",");
	strcpy(m_szModName,pTemp);
	pTemp = strtok(NULL,",");
	if (pTemp)
		strcpy(m_szStyleName,pTemp);

	if ( bNewSkin )
	{
		uint32 cSkins = 0;
		uint32 cHeads = 0;

		char szTag[128];
		char szValue[128];
		sprintf(szTag, "%s_%s", temp, m_szStyleName);
		_strlwr(szTag);

		m_pSkinCtrl->RemoveAll();
		m_pHeadCtrl->RemoveAll();

		char szRestoreSkin[256];
		char szRestoreHead[256];

		strcpy(szRestoreSkin, m_szPlayerSkin);
		*strchr(szRestoreSkin, ',') = 0;
		strcpy(szRestoreHead, m_szPlayerHead);
		*strchr(szRestoreHead, ',') = 0;

		if (g_pModelButeMgr->GetButeMgr()->Exist(szTag))
		{
			sprintf(szValue, "Skin%d", cSkins);
			while ( g_pModelButeMgr->GetButeMgr()->Exist(szTag, szValue) )
			{
				char szName[256];
				strcpy(szName, (const char*)g_pModelButeMgr->GetButeMgr()->GetString(szTag, szValue));
				char* pch = strchr(szName, ',');
				*pch++ = 0;
				strcpy(m_aszSkins[cSkins], pch);

				HSTRING hstr = g_pLTClient->CreateString(szName);
				m_pSkinCtrl->AddString(hstr);
				g_pLTClient->FreeString(hstr);

				if ( m_bRestoreSkinHead )
				{
					if ( !strcmp(szName, szRestoreSkin) )
					{
						m_nSkinNum = cSkins;
						m_pSkinCtrl->UpdateData(LTFALSE);
					}
				}

				cSkins++;
				sprintf(szValue, "Skin%d", cSkins);
			}

			sprintf(szValue, "Head%d", cHeads);
			while ( g_pModelButeMgr->GetButeMgr()->Exist(szTag, szValue) )
			{
				char szName[256];
				strcpy(szName, (const char*)g_pModelButeMgr->GetButeMgr()->GetString(szTag, szValue));
				char* pch = strchr(szName, ',');
				*pch++ = 0;
				strcpy(m_aszHeads[cHeads], pch);

				HSTRING hstr = g_pLTClient->CreateString(szName);
				m_pHeadCtrl->AddString(hstr);
				g_pLTClient->FreeString(hstr);

				if ( m_bRestoreSkinHead )
				{
					if ( !strcmp(szName, szRestoreHead) )
					{
						m_nHeadNum = cHeads;
						m_pHeadCtrl->UpdateData(LTFALSE);
					}
				}

				cHeads++;
				sprintf(szValue, "Head%d", cHeads);
			}
		}

		ASSERT(cSkins != 0 && cHeads != 0);
	}

	m_bRestoreSkinHead = LTFALSE;

	BSCREATESTRUCT bcs;
    LTVector vPos, vU, vR, vF, vTemp, vScale(1.0f,1.0f,1.0f);
    LTRotation rRot;

	char modName[128];
	char animName[128];
	char skinName[128];
	char skin2Name[128];

	if ( bNewSkin )
	{
		sprintf(m_szPlayerSkin, "%s,%s", g_pLTClient->GetStringData(m_pSkinCtrl->GetString(m_nSkinNum)), m_aszSkins[m_nSkinNum]);
		sprintf(m_szPlayerHead, "%s,%s", g_pLTClient->GetStringData(m_pHeadCtrl->GetString(m_nHeadNum)), m_aszHeads[m_nHeadNum]);
	}

	g_pLayoutMgr->GetFolderCustomString((eFolderID)m_nFolderID,"CharAnim",animName,sizeof(animName));

	ModelId eModelId = g_pModelButeMgr->GetModelId(m_szModName);
	ModelStyle	eModelStyle = g_pModelButeMgr->GetStyle(m_szStyleName);
	const char* pFilename = g_pModelButeMgr->GetMultiModelFilename(eModelId, eModelStyle);
	SAFE_STRCPY(modName, pFilename);
	const char* pSkin = strchr(m_szPlayerSkin, ',')+1;
	SAFE_STRCPY(skinName, pSkin);
	const char* pSkin2 = strchr(m_szPlayerHead, ',')+1;
	SAFE_STRCPY(skin2Name, pSkin2);

    g_pLTClient->GetObjectPos(hCamera, &vPos);
    g_pLTClient->GetObjectRotation(hCamera, &rRot);
    g_pLTClient->GetRotationVectors(&rRot, &vU, &vR, &vF);

	VEC_SET(vScale,1.0f,1.0f,1.0f);
	VEC_MULSCALAR(vScale, vScale, g_pLayoutMgr->GetFolderCustomFloat((eFolderID)m_nFolderID,"CharScale"));

    LTVector vModPos = g_pLayoutMgr->GetFolderCustomVector((eFolderID)m_nFolderID,"CharPos");
    LTFLOAT fRot = g_pLayoutMgr->GetFolderCustomFloat((eFolderID)m_nFolderID,"CharRotation");
	fRot  = MATH_PI + DEG2RAD(fRot);
    g_pLTClient->RotateAroundAxis(&rRot, &vU, fRot);

	VEC_MULSCALAR(vTemp, vF, vModPos.z);
	VEC_MULSCALAR(vTemp, vTemp, g_pInterfaceResMgr->GetXRatio());
	VEC_ADD(vPos, vPos, vTemp);

	VEC_MULSCALAR(vTemp, vR, vModPos.x);
	VEC_ADD(vPos, vPos, vTemp);

	VEC_MULSCALAR(vTemp, vU, vModPos.y);
	VEC_ADD(vPos, vPos, vTemp);

	VEC_COPY(bcs.vPos, vPos);
    bcs.rRot = rRot;
	VEC_COPY(bcs.vInitialScale, vScale);
	VEC_COPY(bcs.vFinalScale, vScale);
	VEC_SET(bcs.vInitialColor, 1.0f, 1.0f, 1.0f);
	VEC_SET(bcs.vFinalColor, 1.0f, 1.0f, 1.0f);
    bcs.bUseUserColors = LTTRUE;

	bcs.pFilename = modName;
	bcs.pSkin = skinName;
	bcs.pSkin2 = skin2Name;
	bcs.dwFlags = FLAG_VISIBLE | FLAG_FOGDISABLE | FLAG_NOLIGHT;

	bcs.nType = OT_MODEL;
	bcs.fInitialAlpha = 1.0f;
	bcs.fFinalAlpha = 1.0f;
	bcs.fLifeTime = 1000000.0f;
    bcs.bLoop = LTTRUE;


	if (m_CharSFX.Init(&bcs))
	{
        m_CharSFX.CreateObject(g_pLTClient);
		g_pInterfaceMgr->AddInterfaceSFX(&m_CharSFX, IFX_WORLD);
		if (m_CharSFX.GetObject())
		{
            HMODELANIM  hAnim = g_pLTClient->GetAnimIndex(m_CharSFX.GetObject(),animName);
			if (hAnim != -1)
                g_pLTClient->SetModelAnimation(m_CharSFX.GetObject(),hAnim);

			ClearAttachFX();

			int reqID[MAX_INT_ATTACHMENTS];
			int numReq = g_pAttachButeMgr->GetRequirementIDs(m_szModName,m_szStyleName,reqID,MAX_INT_ATTACHMENTS);
			for (int i = 0; i < numReq; i++)
			{
				INT_ATTACH acs;
				acs.fScale = g_pLayoutMgr->GetFolderCustomFloat((eFolderID)m_nFolderID,"CharScale");
				acs.nAttachmentID = g_pAttachButeMgr->GetRequirementAttachment(reqID[i]);
				CString socket = g_pAttachButeMgr->GetRequirementSocket(reqID[i]);
				acs.pszSocket = (char *)(LPCTSTR)socket;

				CreateAttachFX(&acs);
			}
			int numAtt = g_pLayoutMgr->GetFolderNumAttachments((eFolderID)m_nFolderID);
			for (i = 0; i < numAtt; i++)
			{
				char szTemp[128];
				char *pName = LTNULL;
				char *pSocket = LTNULL;
				g_pLayoutMgr->GetFolderAttachment( (eFolderID)m_nFolderID, i, szTemp, 128);

				pName = strtok(szTemp,";");
				pSocket = strtok(NULL,";");

				INT_ATTACH acs;

				acs.fScale = g_pLayoutMgr->GetFolderCustomFloat((eFolderID)m_nFolderID,"CharScale");
				acs.nAttachmentID = g_pAttachButeMgr->GetAttachmentIDByName(pName);
				acs.pszSocket = pSocket;

				CreateAttachFX(&acs);
			}

		}

        return LTTRUE;

	}

    return LTFALSE;

}
Beispiel #23
0
/************************************************************************************************
* Move ball forward                                                                             *
************************************************************************************************/
void cBall::MoveForward()
{
    this->Pos = vAdd(this->Pos, vScale(this->Dir, this->Vel));
}
Beispiel #24
0
vec2 symmetricBall(float radius) {
    return vScale(rfloat() * radius, uniformUnitCirc());
}
Beispiel #25
0
bool CLTBBouncyChunkFX::Init(ILTClient *pClientDE, FX_BASEDATA *pBaseData, const CBaseFXProps *pProps)
{
	// Perform base class initialisation

	if (!CBaseFX::Init(pClientDE, pBaseData, pProps)) 
		return false;

	LTVector vChunkDir = GetProps()->m_vChunkDir;
	if (pBaseData->m_bUseTargetData)
	{
		vChunkDir = pBaseData->m_vTargetNorm;
	}

	LTVector vPos;
	LTRotation rRot;
	if (m_hParent)
	{
		m_pLTClient->GetObjectPos(m_hParent, &vPos);
		m_pLTClient->GetObjectRotation(m_hParent, &rRot);
	}	
	else
	{
		vPos = m_vCreatePos;
		rRot = m_rCreateRot;
	}

	float scale;
	CalcScale(m_tmElapsed, GetProps()->m_tmLifespan, &scale);

	LTVector vScale(scale, scale, scale);

	ObjectCreateStruct ocs;
	INIT_OBJECTCREATESTRUCT(ocs);

	ocs.m_ObjectType		= OT_MODEL;
	ocs.m_Flags				= FLAG_NOLIGHT | FLAG_VISIBLE;
	ocs.m_Pos				= vPos + GetProps()->m_vOffset;
	ocs.m_Rotation			= rRot;
	ocs.m_Scale				= vScale;
	strcpy(ocs.m_Filename, GetProps()->m_sModelName);
	strcpy(ocs.m_SkinName, GetProps()->m_sSkinName);

	m_hBouncyChunk = m_pLTClient->CreateObject(&ocs);

	// Setup an initial vector for the velocity

	LTVector vOther;
	vOther.x = 1.0f;
	vOther.y = 0.0f;
	vOther.z = 1.0f;
	vOther.Norm();

	LTVector vRight = vChunkDir.Cross(vOther);
	LTVector vUp    = vRight.Cross(vOther);

	m_vVel = vRight * (-GetProps()->m_fChunkSpread + (float)(rand() % (int)(GetProps()->m_fChunkSpread * 2.0f)));
	m_vVel += vUp * (-GetProps()->m_fChunkSpread + (float)(rand() % (int)(GetProps()->m_fChunkSpread * 2.0f)));
	m_vVel += vChunkDir * GetProps()->m_fChunkSpeed;
	m_vVel.Norm(GetProps()->m_fChunkSpeed);

	// Create the base object

	CreateDummyObject();
		
	// Success !!

	return true;
}
void CFolderWeaponControls::CreateModelSFX()
{
	// no model = no SFX
	if (!strlen(m_szModel)) return;

	HOBJECT hCamera = g_pGameClientShell->GetInterfaceCamera();
	if (!hCamera) return;


	BSCREATESTRUCT bcs;

    LTVector vPos, vU, vR, vF, vTemp, vScale(1.0f,1.0f,1.0f);
    LTRotation rRot;

    g_pLTClient->GetObjectPos(hCamera, &vPos);
    g_pLTClient->GetObjectRotation(hCamera, &rRot);
    g_pLTClient->GetRotationVectors(&rRot, &vU, &vR, &vF);

    g_pLTClient->RotateAroundAxis(&rRot, &vU, MATH_HALFPI);
    g_pLTClient->RotateAroundAxis(&rRot, &vR, -0.3f);

	VEC_MULSCALAR(vScale, vScale, m_fScale);

    LTVector vModPos = g_pLayoutMgr->GetFolderCustomVector((eFolderID)m_nFolderID,"ModelPos");
	VEC_ADD(vModPos,vModPos,m_vOffset);

	VEC_MULSCALAR(vTemp, vF, vModPos.z);
	VEC_MULSCALAR(vTemp, vTemp, g_pInterfaceResMgr->GetXRatio());
	VEC_ADD(vPos, vPos, vTemp);

	VEC_MULSCALAR(vTemp, vR, vModPos.x);
	VEC_ADD(vPos, vPos, vTemp);

	VEC_MULSCALAR(vTemp, vU, vModPos.y);
	VEC_ADD(vPos, vPos, vTemp);


	VEC_COPY(bcs.vPos, vPos);
    bcs.rRot = rRot;
	VEC_COPY(bcs.vInitialScale, vScale);
	VEC_COPY(bcs.vFinalScale, vScale);
	VEC_SET(bcs.vInitialColor, 1.0f, 1.0f, 1.0f);
	VEC_SET(bcs.vFinalColor, 1.0f, 1.0f, 1.0f);
    bcs.bUseUserColors = LTTRUE;

	bcs.pFilename = m_szModel;
	bcs.pSkin = m_szSkin;
	bcs.dwFlags = FLAG_VISIBLE | FLAG_FOGDISABLE | FLAG_NOLIGHT;
	bcs.nType = OT_MODEL;
	bcs.fInitialAlpha = 1.0f;
	bcs.fFinalAlpha = 1.0f;
	bcs.fLifeTime = 1000000.0f;

	if (m_ModelSFX.Init(&bcs))
	{
        m_ModelSFX.CreateObject(g_pLTClient);
		g_pInterfaceMgr->AddInterfaceSFX(&m_ModelSFX, IFX_NORMAL);
		m_fSFXRot = g_pLayoutMgr->GetFolderCustomFloat((eFolderID)m_nFolderID,"ModelRotSpeed");
	}

}
Beispiel #27
0
bool CFallingStuffFX::Update(float tmFrameTime)
{
    // Base class update first

    m_vLastPos = m_vPos;

    if (!CBaseFX::Update(tmFrameTime))
        return false;

    //increment our emission time by the elapsed frame time
    m_tmElapsedEmission += tmFrameTime;

    if (!IsShuttingDown() && !IsSuspended() && (m_tmElapsedEmission > GetProps()->m_tmFallingStuffFXEmission))
    {
        ObjectCreateStruct ocs;
        INIT_OBJECTCREATESTRUCT(ocs);

        LTVector vScale;
        vScale.Init(m_scale, m_scale, m_scale);

        LTVector vInterp;
        LTVector vInterpCur  = m_vPos;

        // Calculate interpolant for particle system

        if (GetProps()->m_nFallingStuffFXEmission)
        {
            vInterp = m_vPos - m_vLastPos;
            vInterp /= (float)GetProps()->m_nFallingStuffFXEmission;
        }

        for (uint32 i = 0; i < GetProps()->m_nFallingStuffFXEmission; i ++)
        {
            ocs.m_ObjectType		= OT_SPRITE;
            ocs.m_Flags				= FLAG_VISIBLE | FLAG_NOLIGHT | FLAG_ROTATABLESPRITE;

            // Compute the initial position

            float xRand = GetProps()->m_fRadius * ((-10000.0f + (rand() % 20000)) / 10000.0f);
            float zRand = GetProps()->m_fRadius * ((-10000.0f + (rand() % 20000)) / 10000.0f);

            ocs.m_Pos = m_vPos + (m_vRight * xRand) + (m_vUp * zRand);

            ocs.m_Scale				= vScale;
            strcpy(ocs.m_Filename, GetProps()->m_sSpriteName);

            // Move the start point

            vInterpCur += vInterp;

            HLOCALOBJ hNewSprite = m_pLTClient->CreateObject(&ocs);

            if (hNewSprite)
            {
                // Create a new sprite

                FALLING_THING *pNewSprite = debug_new( FALLING_THING );

                if (GetProps()->m_nImpactCreate)
                {
                    if (g_dwSplash > (uint32)GetProps()->m_nImpactCreate)
                    {
                        pNewSprite->m_bSplash = true;
                        g_dwSplash = 0;
                    }
                    else
                    {
                        pNewSprite->m_bSplash = false;
                    }
                }
                else
                {
                    pNewSprite->m_bSplash = false;
                }

                g_dwSplash ++;

                if (pNewSprite)
                {
                    LTVector v;

                    // Compute the initial velocity

                    v = m_vPlaneDir * GetProps()->m_fVel;

                    pNewSprite->m_hObject	= hNewSprite;
                    pNewSprite->m_vVel		= v;
                    pNewSprite->m_tmElapsed	= 0.0f;
                    pNewSprite->m_vPos		= ocs.m_Pos;
                    pNewSprite->m_vLastPos	= ocs.m_Pos;

                    m_collSprites.AddTail(pNewSprite);
                }
            }
        }

        m_tmElapsedEmission = 0.0f;

        // And store the last position

        m_vLastPos = m_vPos;
    }

    LTMatrix mSpin;

    if (GetProps()->m_bUseSpin)
    {
        // Setup rotation

        LTMatrix vRight;
        LTMatrix vUp;
        LTMatrix vForward;
        LTMatrix vTmp;

        Mat_SetupRot(&vRight, &m_vRight, m_xRot);
        Mat_SetupRot(&vUp, &m_vUp, m_yRot);
        Mat_SetupRot(&vForward, &m_vPlaneDir, m_zRot);

        MatMul(&vTmp, &vRight, &vUp);
        MatMul(&mSpin, &vTmp, &vForward);

        m_xRot += GetProps()->m_vRotAdd.x * tmFrameTime;
        m_yRot += GetProps()->m_vRotAdd.y * tmFrameTime;
        m_zRot += GetProps()->m_vRotAdd.z * tmFrameTime;
    }

    // Get the camera rotation

    LTRotation orient;
    m_pLTClient->GetObjectRotation(m_hCamera, &orient);

    LTRotation dRot(orient);

    LTVector vF = orient.Forward();

    float rot = (float)atan2(vF.x, vF.z);

    // Update the sprites....

    CLinkListNode<FALLING_THING *> *pNode = m_collSprites.GetHead();
    CLinkListNode<FALLING_THING *> *pDelNode;

    while (pNode)
    {
        pDelNode = NULL;

        FALLING_THING *pSprite = pNode->m_Data;

        //adjust our elapsed time
        pSprite->m_tmElapsed += tmFrameTime;

        // Check for expiration

        if (pSprite->m_tmElapsed > GetProps()->m_tmSpriteLifespan)
        {
            // Destroy this object

            m_pLTClient->RemoveObject(pSprite->m_hObject);

            pDelNode = pNode;
        }
        else
        {
            // Update !!

            pSprite->m_vLastPos = pSprite->m_vPos;

            pSprite->m_vPos += (pSprite->m_vVel * tmFrameTime);

            // Rotate if neccessary

            TVector3<float> vPos = pSprite->m_vPos;

            if (GetProps()->m_bUseSpin)
            {
                MatVMul_InPlace(&mSpin, &vPos);
            }

            // Add in wind

            vPos += (GetProps()->m_vWind * GetProps()->m_fWindAmount) * tmFrameTime;

            // Setup the new sprite position

            LTVector vPos2 = vPos;
            m_pLTClient->SetObjectPos(pSprite->m_hObject, &vPos2);


            // Setup the colour

            float r, g, b, a;

            m_pLTClient->GetObjectColor(pSprite->m_hObject, &r, &g, &b, &a);
            CalcColour(pSprite->m_tmElapsed, GetProps()->m_tmSpriteLifespan, &r, &g, &b, &a);
            m_pLTClient->SetObjectColor(pSprite->m_hObject, r, g, b, a);

            // Setup the scale

            float scale = 0.1f;

            CalcScale(pSprite->m_tmElapsed, GetProps()->m_tmSpriteLifespan, &scale);

            LTVector vScale;
            vScale.Init(scale, scale * GetProps()->m_fStretchMul, scale);
            m_pLTClient->SetObjectScale(pSprite->m_hObject, &vScale);

            // Setup the rotation

            dRot = LTRotation(0, 0, 0, 1);
            LTRotation orient(dRot);

            orient.Rotate( orient.Up(), rot );

            m_pLTClient->SetObjectRotation(pSprite->m_hObject, &orient);

            // Check to see if we need to start a splash sprite

            if (pSprite->m_bSplash)
            {
                ClientIntersectQuery ciq;
                ClientIntersectInfo  cii;

                ciq.m_From		= pSprite->m_vLastPos;
                ciq.m_To		= pSprite->m_vPos;

                if ((GetProps()->m_sImpactSpriteName[0]) && (m_pLTClient->IntersectSegment(&ciq, &cii)))
                {
                    // Create a splash sprite

                    SPLASH *pSplash = debug_new( SPLASH );

                    ObjectCreateStruct ocs;
                    INIT_OBJECTCREATESTRUCT(ocs);

                    LTVector vScale;
                    vScale.Init(0.0f, 0.0f, 0.0f);

                    ocs.m_ObjectType = OT_SPRITE;
                    ocs.m_Flags		 = FLAG_VISIBLE | FLAG_ROTATABLESPRITE | FLAG_NOLIGHT;
                    ocs.m_Pos		 = cii.m_Point + (cii.m_Plane.m_Normal * 2.0f);
                    ocs.m_Scale		 = vScale;

                    LTRotation dOrient( cii.m_Plane.m_Normal, LTVector(0.0f, 1.0f, 0.0f) );

                    strcpy(ocs.m_Filename, GetProps()->m_sImpactSpriteName);

                    pSplash->m_hObject = m_pLTClient->CreateObject(&ocs);
                    pSplash->m_scale = 0.0f;

                    LTRotation orient(dRot);
                    m_pLTClient->SetObjectRotation(pSplash->m_hObject, &orient);

                    pSplash->m_tmElapsed = 0.0f;

                    m_collSplashes.AddTail(pSplash);

                    // Destroy this object

                    m_pLTClient->RemoveObject(pSprite->m_hObject);

                    // Delete the sprite

                    pDelNode = pNode;
                }
            }
        }

        pNode = pNode->m_pNext;

        if (pDelNode) m_collSprites.Remove(pDelNode);
    }

    // Update our splashes

    CLinkListNode<SPLASH *> *pSplashNode = m_collSplashes.GetHead();

    while (pSplashNode)
    {
        CLinkListNode<SPLASH *> *pDelNode = NULL;

        SPLASH *pSplash = pSplashNode->m_Data;

        //update the elapsed time on the splash
        pSplash->m_tmElapsed += tmFrameTime;

        // Calculate the new scale

        float scale = GetProps()->m_fImpactScale1 + ((GetProps()->m_fImpactScale2 - GetProps()->m_fImpactScale1) * (pSplash->m_tmElapsed / GetProps()->m_tmImpactLifespan));

        LTVector vScale(scale, scale, scale);
        m_pLTClient->SetObjectScale(pSplash->m_hObject, &vScale);

        float r, g, b, a;

        m_pLTClient->GetObjectColor(pSplash->m_hObject, &r, &g, &b, &a);

        a = (float)(int)(pSplash->m_tmElapsed / GetProps()->m_tmImpactLifespan);
        if (a < 0.0f) a = 0.0f;
        if (a > 1.0f) a = 1.0f;

        m_pLTClient->SetObjectColor(pSplash->m_hObject, r, g, b, a);

        if (pSplash->m_tmElapsed > GetProps()->m_tmImpactLifespan)
        {
            m_pLTClient->RemoveObject(pSplash->m_hObject);
            pDelNode = pSplashNode;
        }

        pSplashNode = pSplashNode->m_pNext;

        if (pDelNode) m_collSplashes.Remove(pDelNode);
    }

    // Success !!

    return true;
}
Beispiel #28
0
//===============================================
//     Unit Tests
//===============================================
int main() {
    // set for command line argument -t to run unit tests.
    bool test = true;

    if (test) {
        std::cout<<"\n=================\nBegin UNIT TESTS\n=================\n\n";
        Light::Light n = *new Light::Light(0, 1, 1, 0, 0.5, 0.5, 0.5);
        n.print();

        Intersect::Intersect i = *new Intersect::Intersect();
        if(i.isHit()) {
            std::cout<<"INCORRECT! hit is true.\n\n";
        }
        else {
            std::cout<<"CORRECT! hit is false.\n\n";
            i.setHit(true);
        }
        if(i.isHit()) {
            std::cout<<"CORRECT! hit is true.\n\n";
        }
        else {
            std::cout<<"INCORRECT! hit is false.\n\n";
        }
        std::vector<float> ptest(3);
        ptest[0] = 0;
        ptest[1] = 1;
        ptest[2] = 2;
        i.setPoint(ptest);
        std::vector<float> p = i.getPoint();
        std::cout<< "[" << p[0] << ", " << p[1] << ", " << p[2] << "]\n";

        Vertex::Vertex a = *new Vertex::Vertex(0,0,0);
        Vertex::Vertex b = *new Vertex::Vertex(1,0,0);
        Vertex::Vertex c = *new Vertex::Vertex(0,1,0);
        a.print();
        a = a.sub(b);
        a.print();
        std::vector<float> d = c.toVec();
        std::cout<<"vec ["<< d[0] << ", " << d[1] << ", " << d[2] << "]\n";
        Vertex::Vertex e1 = *new Vertex::Vertex(d);
        e1.print();
        Vertex a1 = *new Vertex::Vertex(0,1,0);
        Vertex b1 = *new Vertex::Vertex(1,-1,0);
        Vertex c1 = *new Vertex::Vertex(-1,-1,0);
        Triangle t = *new Triangle::Triangle(a1,b1,c1);
        p[0] = 0;
        p[1] = 0;
        p[2] = 0;
        std::vector<float> e(3);
        e[0] = 0;
        e[1] = 0;
        e[2] = 3;

        Ray::Ray r = *new Ray::Ray(e, p);
        i = t.intersect(r);
        if (i.isHit()) {
            std::cout<<"Triangle Intersected - OKAY\n";
        }
        Sphere::Sphere s = *new Sphere::Sphere(1, p);
        if (s.intersect(r).isHit()) {
            std::cout<<"Sphere Intersected - OKAY\n";
        }


        e[0] = 0;
        e[1] = -4;
        e[2] = -4;
        p[0] = 1;
        p[1] = 1;
        p[2] = -1;
        r.setEye(e);
        r.setPoint(p);
        std::cout<<"projected ";
        vPrint(r.project(1.5));


        PPM* ppm = new PPM(640, 480, 255);
        int val;
        for (float h = 0; h<480; h++) {
            for (float w =0; w<640; w++) {
                val = h;//std::min(255, (int)((w/639)*255.0f));
                ppm->addPixel(*(new Pixel::Pixel(val, val, val)));
            }
        }
        ppm->save("output");
        /*
        for (float h = 0; h < 3; h++) {
        	for (float w = 0; w< ppm->getW(); w++) {
        		std::cout<<w<<" ";
        		ppm->getPixel(w, h).print();
        	}
        }
        */

        std::cout<<"End PPM tests\n";
        Pixel::Pixel px = *new Pixel::Pixel(255, 255, 255);
        Pixel::Pixel black = *new Pixel::Pixel(0,0,0);
        Pixel::Pixel pfloat = *new Pixel::Pixel(1.0f, 0.9f, 0.05f);
        Pixel::Pixel pmax = *new Pixel::Pixel(2.0f, 1.0f, 0.5f);
        px.print();
        black.print();
        black.add(px);
        black.print();
        pfloat.print();
        pmax.print();


        std::vector<float> test1(3);
        test1[0] = 1;
        test1[1] = 0;
        test1[2] = 0.5;
        std::vector<float> test2(3);
        test2[0] = 0;
        test2[1] = 1;
        test2[2] = 0.5;
        std::cout<<vDot(test1, test2)<<"\n";
        vPrint(vSub(test1, test2));
        vPrint(vAdd(test1, test2));
        vPrint(vMult(test1, test2));
        vPrint(normalize(test1));
        vPrint(normalize(test2));
        vPrint(vCross(test1, test2));
        vPrint(vScale(-1, test1));

        std::cout<<"\n=================\nEnd UNIT TESTS\n=================\n\n";

        return 0;
    }
    else {
        return 0;
    }
}
Beispiel #29
0
void Box3D::UpdateTransformMatrix()
{
	m_TransformMatrix.Identity();

	if ( m_TranslateMode == modeNone )
	{
		return;
	}
	else if ( m_TranslateMode == modeMove )
	{
		m_TransformMatrix.SetTranslation( m_vTranslation );
		return;
	}
	else if ( m_TranslateMode == modeScale )
	{
		Vector vScale( 1,1,1);
		Vector vMove(0,0,0);
		Vector vSize = bmaxs-bmins;

		for ( int i=0; i<3; i++ )
		{
			float handle = m_TranslateHandle[i];

			if ( vSize[i] == 0 )
				continue;

			if ( handle > 0 )
			{
				vScale[i] = (m_vTranslation[i]+vSize[i]) / vSize[i];
				vMove[i] = m_vTranslation[i] / 2;
			}
			else if ( handle < 0 )
			{
				vScale[i] = (-m_vTranslation[i]+vSize[i]) / vSize[i];
 				vMove[i] = m_vTranslation[i] / 2;
			}
		}

		m_TransformMatrix = m_TransformMatrix.Scale( vScale );
		m_TransformMatrix.SetTranslation( vMove );
	}
	else if ( m_TranslateMode == modeShear )
	{
		Vector vSize = bmaxs-bmins;

		int axisS = -1; // shear axis that wont change
		int axisA = -1; // first shear axis
		int axisB = -1; // second shear axis
		
		for ( int i=0; i<3; i++ )
		{
 			float handle = m_TranslateHandle[i];

			if ( handle > 0 )
			{
				Assert( axisS == -1);
				axisS = i;
			}
			else if ( handle < 0 )
			{
				Assert( axisS == -1);
				axisS = i;
				vSize *= -1;
			}
			else
			{
				if ( axisA == -1 )
					axisA = i;
				else
					axisB = i;
			}
		}

		Assert( (axisA!=-1) && (axisB!=-1) && (axisS!=-1) );
		
 		m_TransformMatrix.m[axisA][axisS] = (m_vTranslation[axisA])/(vSize[axisS]);
 		m_TransformMatrix.m[axisB][axisS] = (m_vTranslation[axisB])/(vSize[axisS]);
	}
	else if ( m_TranslateMode == modeRotate )
	{
		QAngle angle = *(QAngle*)&m_vTranslation; // buuuhhh
 		m_TransformMatrix.SetupMatrixOrgAngles( vec3_origin, angle );
	}

	// apply m_vTranslationFixPoint offset

	Vector offset;
	m_TransformMatrix.V3Mul( m_vTranslationFixPoint, offset );
	offset = m_vTranslationFixPoint - offset;

	m_TransformMatrix.m[0][3] += offset[0];
	m_TransformMatrix.m[1][3] += offset[1];
	m_TransformMatrix.m[2][3] += offset[2];
}
Beispiel #30
0
LTBOOL CSearchLightFX::Update()
{
    if (!m_pClientDE || !m_hServerObject || m_bWantRemove || !m_hBeam) return LTFALSE;

    uint32 dwFlags = 0;

	// Update the lens flare...

	m_LensFlare.Update();

	// Hide/show the fx if necessary...

	if (m_hServerObject)
	{
        uint32 dwUserFlags;
		m_pClientDE->GetObjectUserFlags(m_hServerObject, &dwUserFlags);

		if (!(dwUserFlags & USRFLG_VISIBLE))  // Hide fx
		{
			if (m_hBeam)
			{
				dwFlags = m_pClientDE->GetObjectFlags(m_hBeam);
				m_pClientDE->SetObjectFlags(m_hBeam, dwFlags & ~FLAG_VISIBLE);
			}
			if (m_hLight)
			{
				dwFlags = m_pClientDE->GetObjectFlags(m_hLight);
				m_pClientDE->SetObjectFlags(m_hLight, dwFlags & ~FLAG_VISIBLE);
			}

            return LTTRUE;
		}
		else  // Make all fx visible
		{
			if (m_hBeam)
			{
				dwFlags = m_pClientDE->GetObjectFlags(m_hBeam);
				m_pClientDE->SetObjectFlags(m_hBeam, dwFlags | FLAG_VISIBLE);
			}
			if (m_hLight)
			{
				dwFlags = m_pClientDE->GetObjectFlags(m_hLight);
				m_pClientDE->SetObjectFlags(m_hLight, dwFlags | FLAG_VISIBLE);
			}
		}
	}


	// Update the position/rotation of the beam...

    LTVector vPos;
	m_pClientDE->GetObjectPos(m_hServerObject, &vPos);

    LTRotation rRot;
	m_pClientDE->GetObjectRotation(m_hServerObject, &rRot);

    LTVector vU, vR, vF;
	m_pClientDE->GetRotationVectors(&rRot, &vU, &vR, &vF);


	// See how long to make the beam...

    LTVector vDest = vPos + (vF * m_cs.fBeamLength);

	IntersectInfo iInfo;
	IntersectQuery qInfo;
	qInfo.m_Flags		= INTERSECT_OBJECTS | IGNORE_NONSOLID;
	qInfo.m_FilterFn	= AttackerLiquidFilterFn;
	qInfo.m_pUserData	= m_hServerObject;
	qInfo.m_From		= vPos;
	qInfo.m_To			= vDest;

    if (g_pLTClient->IntersectSegment(&qInfo, &iInfo))
	{
		vDest = iInfo.m_Point;
	}

    LTVector vDir = vDest - vPos;
    LTFLOAT fDistance = vDir.Mag();
	vDir.Norm();

    LTVector vNewPos = vPos + vDir * fDistance/2.0f;
	m_pClientDE->AlignRotation(&rRot, &vDir, NULL);

	if (m_cs.fBeamRotTime > 0.0f)
	{
		m_fBeamRotation += (360.0f/m_cs.fBeamRotTime * g_pGameClientShell->GetFrameTime());
		m_fBeamRotation = m_fBeamRotation > 360.0f ? m_fBeamRotation - 360.0f : m_fBeamRotation;
		m_pClientDE->RotateAroundAxis(&rRot, &vDir, DEG2RAD(m_fBeamRotation));
	}

	m_pClientDE->SetObjectRotation(m_hBeam, &rRot);
	m_pClientDE->SetObjectPos(m_hBeam, &vNewPos);

    LTVector vScale(m_cs.fBeamRadius, m_cs.fBeamRadius, fDistance);
	m_pClientDE->SetObjectScale(m_hBeam, &vScale);


	// Move the dynamic light...

	if (m_hLight)
	{
		vDest -= (vDir * 5.0f);
		m_pClientDE->SetObjectPos(m_hLight, &vDest);
	}

    return LTTRUE;
}