void CDivideProxy::OnBind( void *pC_BaseEntity ) { Assert( m_pSrc1 && m_pSrc2 && m_pResult ); MaterialVarType_t resultType; int vecSize; ComputeResultType( resultType, vecSize ); switch( resultType ) { case MATERIAL_VAR_TYPE_VECTOR: { Vector a, b, c; m_pSrc1->GetVecValue( a.Base(), vecSize ); m_pSrc2->GetVecValue( b.Base(), vecSize ); VectorDivide( a, b, c ); m_pResult->SetVecValue( c.Base(), vecSize ); } break; case MATERIAL_VAR_TYPE_FLOAT: if (m_pSrc2->GetFloatValue() != 0) { SetFloatResult( m_pSrc1->GetFloatValue() / m_pSrc2->GetFloatValue() ); } else { SetFloatResult( m_pSrc1->GetFloatValue() ); } break; case MATERIAL_VAR_TYPE_INT: if (m_pSrc2->GetIntValue() != 0) { m_pResult->SetFloatValue( m_pSrc1->GetIntValue() / m_pSrc2->GetIntValue() ); } else { m_pResult->SetFloatValue( m_pSrc1->GetIntValue() ); } break; } if ( ToolsEnabled() ) { ToolFramework_RecordMaterialParams( GetMaterial() ); } }
void translateToCenter() { int i; particle_t *p; VectorNew(pos); VectorZero(pos); for (i = 0; i < state.particleCount; i++) { p = getParticleCurrentFrame(i); VectorAdd(pos, p->pos, pos); } VectorDivide(pos, state.particleCount, pos); glTranslatef(-pos[0], -pos[1], -pos[2]); VectorCopy(pos, view.lastCenter); }
static void ComputeAmbientFromSurface( dface_t* pFace, directlight_t* pSkylight, Vector& radcolor ) { texinfo_t* pTex = &texinfo[pFace->texinfo]; if (pTex) { // If we hit the sky, use the sky ambient if (pTex->flags & SURF_SKY) { if (pSkylight) { // add in sky ambient VectorDivide( pSkylight->light.intensity, 255.0f, radcolor ); } } else { VectorMultiply( radcolor, dtexdata[pTex->texdata].reflectivity, radcolor ); } } }
//----------------------------------------------------------------------------- // Places Detail Objects on a face //----------------------------------------------------------------------------- static void EmitDetailObjectsOnFace( dface_t* pFace, DetailObject_t& detail ) { if (pFace->numedges < 3) return; // We're going to pick a bunch of random points, and then probabilistically // decide whether or not to plant a detail object there. // Turn the face into a bunch of polygons, and compute the area of each int* pSurfEdges = &dsurfedges[pFace->firstedge]; int vertexIdx = (pSurfEdges[0] < 0); int firstVertexIndex = dedges[abs(pSurfEdges[0])].v[vertexIdx]; dvertex_t* pFirstVertex = &dvertexes[firstVertexIndex]; for (int i = 1; i < pFace->numedges - 1; ++i ) { int vertexIdx = (pSurfEdges[i] < 0); dedge_t* pEdge = &dedges[abs(pSurfEdges[i])]; // Compute two triangle edges Vector e1, e2; VectorSubtract( dvertexes[pEdge->v[vertexIdx]].point, pFirstVertex->point, e1 ); VectorSubtract( dvertexes[pEdge->v[1 - vertexIdx]].point, pFirstVertex->point, e2 ); // Compute the triangle area Vector areaVec; CrossProduct( e1, e2, areaVec ); float normalLength = areaVec.Length(); float area = 0.5f * normalLength; // Compute the number of samples to take int numSamples = area * detail.m_Density * 0.000001; // Now take a sample, and randomly place an object there for (int i = 0; i < numSamples; ++i ) { // Create a random sample... float u = rand() / (float)RAND_MAX; float v = rand() / (float)RAND_MAX; if (v > 1.0f - u) { u = 1.0f - u; v = 1.0f - v; assert( u + v <= 1.0f ); } // Compute alpha float alpha = 1.0f; // Select a group based on the alpha value int group = SelectGroup( detail, alpha ); // Now that we've got a group, choose a detail int model = SelectDetail( detail.m_Groups[group] ); if (model < 0) continue; // Got a detail! Place it on the surface... Vector pt, normal; VectorMA( pFirstVertex->point, u, e1, pt ); VectorMA( pt, v, e2, pt ); VectorDivide( areaVec, -normalLength, normal ); PlaceDetail( detail.m_Groups[group].m_Models[model], pt, normal ); } } }
void CVector::Normalise() { VectorDivide(*this, sqrt( x*x + y*y + z*z ), *this); length = 1.0; //TODO this might not be the beeest idea but technically this should be 1.0... }
static int Vector___div (lua_State *L) { Vector c; VectorDivide(*(Vector *)luaL_checkvector(L, 1), luaL_checknumber(L, 2), c); lua_pushvector(L, &c); return 1; }