Exemplo n.º 1
0
Ray Ray::getInConeRay(Vec3f intersection, Vec3f * triangle, int depth, pair <int, int> exceptionTriangle)
{
    Vec3f n = getNormalwithRayComes(triangle, this->direction);
    //find a unit vector in the plane
    Vec3f ex(triangle[0] - intersection);
    ex /= ex.length();

    //another unit vector in the plane to forme a local coordiante
    Vec3f ey = cross(n, ex);
    Vec3f wi(this->position - intersection);
    wi /= wi.length();

    float cosTheta_i = dot(wi, n);
    if(cosTheta_i < -EPS)
        cout << "ERROR in getInConeRaysOut: l'angle theta_i est plus grande que 90, something wrong with the direction" << endl;

    //find a eOnPlane vector unit (which lies on plane)
    float xComponent     = getRandomFloat(-1.0, 1.0);
    float yComponent     = getRandomFloat(-1.0, 1.0);
    Vec3f eOnPlane(xComponent * ex + yComponent * ey);
    eOnPlane /= eOnPlane.length();

    //to ensure the direction Out lies inside the cone
    //dirOut = costheta_i * normal + sintheta_i * eOnPlane
    Vec3f dirOut(cosTheta_i * n + sqrt(1 - cosTheta_i*cosTheta_i) * eOnPlane);
    dirOut /= dirOut.length();

    return Ray(intersection, dirOut, bshRoot, depth, exceptionTriangle);
}
Exemplo n.º 2
0
vector<float> generateTestData()
{
    //Generates a data point either in the range (0.75,0.75) -> (1,1) or (0,0) -> (.25,.25)
    double g = getRandomFloat(0, 1);
    double lb;
    double ub;
    if (g < 0.33)
    {
        lb = 0.8;
        ub = 1.00;
    }
    else if (g < 0.66)
    {
        lb = 0.0;
        ub = 0.2;
    }
    else
    {
        lb = 0.4;
        ub = 0.6;
    }
    vector<float> generatedVector;
    generatedVector.push_back(getRandomFloat(lb, ub));
    generatedVector.push_back(getRandomFloat(lb, ub));
    generatedVector.shrink_to_fit();
    return generatedVector;
}
Exemplo n.º 3
0
float ParticleSystem::getRandomValue(float base, float variance)
{
	float min = base - (variance / 2);
	float max = base + (variance / 2);

	return getRandomFloat(min, max);
}
Exemplo n.º 4
0
    Perceptron::Perceptron(unsigned int newFeatureSpaceDimension)
    {
        for (unsigned int i = 0; i != newFeatureSpaceDimension + 1; ++i)
            weights.push_back(getRandomFloat(-0.05, 0.05));

        featureSpaceDimension = newFeatureSpaceDimension;
    }
Exemplo n.º 5
0
inline f32 getFloatFromValueRange( const CTreeGenerator::SValueRange<f32>& range, s32 seed )
{
    if ( range.IsValue )
        return range.Value;
    
    return getRandomFloat( seed, range.Min, range.Max );
}
Exemplo n.º 6
0
 void main() {
     vec2 gravity = vec2(0.0, -0.0005);
     float max = 0.05;
     float maxSquared = max * max;
     
     outPos = inPos;
     outVel = inVel;
     outVel += gravity;
     
     // limit speed
     float speedSquared = dot(outVel, outVel);
     if (speedSquared > maxSquared) {
         vec2 norm = normalize(outVel);
         outVel *= max;
     }
     
     outPos += outVel;
     
     // keep in frame
     if (inPos.y < -1.0) {
         outPos.x = 0.0;
         outPos.y = 0.0;
         
         // reset velocity and position
         
         // use position to generate random number for velocity direction
         float newFloat = getRandomFloat(inPos);
         
         // use a different vector to generate a random number for velocity length
         vec2 altVec;
         if (inPos.x != 0.0 && inPos.y != 0.0) {
             altVec = inPos + vec2(1.0/inPos.x, 1.0/inPos.y);
         } else {
             altVec = inPos;
         }
         
         float newSpeed = getRandomFloat(altVec);
         newSpeed = mapFloat(newSpeed, 0.0, 1.0, 0.06, 0.15); // make min output number smaller; why does that happen?
         
         outVel = getDir(newFloat);
         outVel *= newSpeed;
         outPos = mousePos;
     }
     
     outCol = inCol;
     gl_Position = vec4(outPos, 0.0, 1.0);
 }
Exemplo n.º 7
0
	void dbRoundPosGenerator::Generate(double dt, dbParticleData *p, size_t startId, size_t endId)
	{
		for (size_t i = startId; i < endId; ++i)
		{
			double ang = getRandomFloat(0.0f, DB_PI*2.0f, 2);
			p->position_[i] = center_ + core::dbVector3(radX_*(float)sin(ang), radY_*(float)cos(ang), 0.f);
			p->velocity_[i] = core::dbVector3();
		}
	}
Exemplo n.º 8
0
 void Game::initVoronoiDiagram()
 {
     Box2 vertexBounds = bounds_;
     vertexBounds.pad(5.0f);
     Box2 triangulationBounds = vertexBounds;
     triangulationBounds.pad(5.0f);
     delauneyTriangulation_ = DelauneyTriangulation(triangulationBounds);
     int subdivCount = 30;
     float subdivWidth = float(vertexBounds.getWidth()) / float(subdivCount);
     float subdivHeight = float(vertexBounds.getHeight()) / float(subdivCount);
     for (int i = 0; i < subdivCount; ++i) {
         for (int j = 0; j < subdivCount; ++j) {
             float x = vertexBounds.p1.x + (float(i) + getRandomFloat()) * subdivWidth;
             float y = vertexBounds.p1.y + (float(j) + getRandomFloat()) * subdivHeight;
             delauneyTriangulation_.addVertex(Vector2(x, y));
         }
     }
     voronoiDiagram_.generate(delauneyTriangulation_);
 }
Exemplo n.º 9
0
//when an enemy loses health, check if they are afraid
bool Follower::addHealth(float _health)
{
	bool boolReturn = Pawn::addHealth(_health);
	//if health was removed and they are below fear health
	if (boolReturn && (_health < 0) && (mHealth < mFearHealth))
	{
		float chance = mHealth / mFearHealth;
		if (getRandomFloat(0.0f, 1.0f) > chance)
			bAfraid = true;
	}
	return boolReturn;
}
Exemplo n.º 10
0
Ray Ray::getRandomRay_Sphere(Vec3f intersection, Vec3f * triangle, int depth, pair <int, int> exceptionTriangle)
{
    Vec3f en = getNormalwithRayComes(triangle, this->direction);

    //find a unit vector in the plane
    Vec3f ex(triangle[0] - intersection);
    ex.normalize();

    //another unit vector in the plane to forme a local coordiante
    Vec3f ey = cross(en, ex);
    ey.normalize();
    
    float angleN = getRandomFloat(0.0, acos(-1.0) / 2);
    float angleXY = getRandomFloat(0.0, 2 * acos(-1.0));
    
    Vec3f dirOut((ex * cos(angleXY) * sin(angleN)) +
                 (ey * sin(angleXY) * sin(angleN)) +
                 (en * cos(angleN)));
    
    dirOut.normalize();
    
    return Ray(intersection, dirOut, bshRoot, depth, exceptionTriangle, this->DBG);
}
Exemplo n.º 11
0
int getActorDefense(character *actor) {
	float defense = actor->statDefense;
	int inventoryIndex = 0;
	item *itmPtr;

	while (inventoryIndex < actor->numberOfItems) {
		itmPtr = actor->inventory[inventoryIndex];

		defense += itmPtr->statDefense;

		inventoryIndex ++;
	}

	defense *= getRandomFloat(.75, 1);

	return (int)(defense + .5);
}
Exemplo n.º 12
0
void Enemy::chooseTarget()
{
	if (!bAttackPlayer)
	{//if only see the follower, attack them
		bPursuingPlayer = false;
	}
	else if (!bAttackFollower)
	{//if only sees the player, attack them
		bPursuingPlayer = true;
	}
	else//else choose randomly between them
	{
		if (getRandomFloat(0.0f, 1.0f) < 0.5f)
			bPursuingPlayer = true;
		else
			bPursuingPlayer = false;
	}
}
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(example_mlst_node_process, ev, data)
{
	static struct etimer et;

	PROCESS_BEGIN();

	//Initialize the mlst-network. Has to be done to open ports, etc.
	mlst_init();	
	eamlst_set_energy_state(ENERGY_STATE);

	while(1) {
		mlst_print_state();
		rsunicast_print_state();
		etimer_set(&et, CLOCK_SECOND * 4 * getRandomFloat(0.5,1.0));
		//uint8_t data[7];
		//mlst_send(&data, sizeof(data));
		PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et));
	}

	PROCESS_END();
}
Exemplo n.º 14
0
void spawnCube()
{
	evil cube;

	cube.dead = false;

	cube.x = getRandomFloat() * 2.f * playFieldWidth - playFieldWidth;
	cube.z = getRandomFloat() * 2.f * playFieldLength - playFieldLength;
	cube.y = getRandomFloat() * (cube_max_Y - cube_min_Y) + cube_min_Y;

	cube.dx = getRandomFloat() * 2.0f - 1.0f;
	cube.dy = getRandomFloat() * 2.0f - 1.0f;
	cube.dz = getRandomFloat() * 2.0f - 1.0f;

	_evilCubes.push_back(cube);
}
Exemplo n.º 15
0
void _actorLogic(character *actor) {
	int moved = 0;

	if (!actor->hp) {
		return;
	}
	
	character *player = getPlayer(), *ptr = CHARACTERS;
	item *weaponPtr = NULL, *actorWeapon = actorGetItemWithFlag(actor, IS_WEAPON);
	int hitActor = 0;
	int nx = actor->x + actor->vx;
	int ny = actor->y + actor->vy;
	int spawnPosition[2];
	
	if (!actor->turns) {
		return;
	}
	
	if (actor->delay > 1) {
		actor->delay --;
		
		return;
	}
	
	actor->turns = 0;
	actor->delay = 0;

	if (actor->nextStanceFlagsToAdd) {
		tickSystemsWithMaskForEntity(getWorld(), actor->entityId, EVENT_ADD_STANCE);

		actor->stanceFlags |= actor->nextStanceFlagsToAdd;
		actor->nextStanceFlagsToAdd = 0x0;
	}

	if (actor->nextStanceFlagsToRemove) {
		tickSystemsWithMaskForEntity(getWorld(), actor->entityId, EVENT_REMOVE_STANCE);

		actor->stanceFlags ^= actor->nextStanceFlagsToRemove;
		
		if (actor->nextStanceFlagsToRemove & IS_STUNNED) {
			if (actor == player) {
				showMessage(5, "You regain composure.", NULL);
			} else {
				showMessage(5, "It regains composure.", NULL);
			}
		} else if (actor->nextStanceFlagsToRemove & IS_HOLDING_LODGED_WEAPON) {
			if (actor == player) {
				showMessage(5, "You dislodge the weapon.", NULL);
			} else {
				showMessage(5, "Something dislodges their weapon.", NULL);
			}
		}
		
		if (actor->nextStanceFlagsToRemove & IS_STUCK_WITH_LODGED_WEAPON) {
			weaponPtr = getItemLodgedInActor(actor);
			
			weaponPtr->itemFlags ^= IS_LODGED;
			weaponPtr->lodgedInActor = NULL;
		}
		
		actor->nextStanceFlagsToRemove = 0x0;
	}
	
	while (ptr != NULL) {
		if (ptr == actor || ptr->hp <= 0) {
			ptr = ptr->next;
			
			continue;
		}
		
		if (ptr->x == nx && ptr->y == ny) {
			hitActor = 1;
			
			break;
		}

		ptr = ptr->next;
	}
	
	if (_checkForTouchedItemAndHandle(actor, nx, ny)) {
		actor->vx = 0;
		actor->vy = 0;
		
		return;
	}

	if (hitActor) {
		actor->vx = 0;
		actor->vy = 0;

		if (attack(actor, ptr)) {
			return;
		}
	} else if (actor->vx || actor->vy) {
		if (actor->stanceFlags & IS_STUCK_WITH_LODGED_WEAPON && getItemLodgedInActor(actor)->owner) {
			printf("Cant move because of stuck weapon.\n");
			
			return;
		}
		
		if (actor->stanceFlags & IS_HOLDING_LODGED_WEAPON) {
			actor->stanceFlags ^= IS_HOLDING_LODGED_WEAPON;
			dropItem(actor, actorWeapon);
			
			printf("Handle letting go of weapon!\n");
			
			showMessage(10, "You let go of the weapon.", NULL);
			
			return;
		}
		
		if (isPositionWalkable(nx, ny)) {
			moved = 1;

			if (actor->aiFlags & IS_VOID_WORM && getRandomFloat(0, 1) > .95) {
				getOpenPositionInRoom(getRandomRoom(), spawnPosition);
				createVoidWorm(spawnPosition[0], spawnPosition[1]);
			}

			if (actor->aiFlags & IS_VOID_WORM) {
				createVoidWormTail(actor->x, actor->y);
			}

			actor->lastX = actor->x;
			actor->lastY = actor->y;
			actor->x = nx;
			actor->y = ny;
			setStance(actor, IS_MOVING);

			if (actor->itemLight) {
				actor->itemLight->fuel -= getLevel();
			}

			if (actor->stanceFlags & IS_STABBING) {
				actor->statStabCount --;

				if (!actor->statStabCount) {
					unsetStance(actor, IS_STABBING);
				}
			}

			TCOD_map_compute_fov(actor->fov, actor->x, actor->y, actor->sightRange, 1, FOV_SHADOW);
		} else {
			if (actor->stanceFlags & IS_MOVING) {
				unsetStance(actor, IS_MOVING);

				if (actor->stanceFlags & IS_STABBING) {
					actor->statStabCount = 0;
					unsetStance(actor, IS_STABBING);
				}
			}
		}
	} else {
		if (actor->stanceFlags & IS_MOVING) {
			unsetStance(actor, IS_MOVING);

			if (actor->stanceFlags & IS_STABBING) {
				actor->statStabCount = 0;
				unsetStance(actor, IS_STABBING);
			}
		}
	}

	if (moved) {
		_checkForItemCollisions(actor);
	}
	
	if (!(actor->aiFlags & IS_IMMUNE_TO_DARKNESS) && _checkIfPositionLit(actor)) {
		return;
	}
	
	if (actor->itemLight) {
		actor->itemLight->x = actor->x;
		actor->itemLight->y = actor->y;
	}

	actor->vx = 0;
	actor->vy = 0;
}
Exemplo n.º 16
0
 float getRandomFloat(float end)
 {
     return getRandomFloat(0.0f, end);
 }
Exemplo n.º 17
0
void CTreeGenerator::appendBranch( const core::matrix4& transform, SBranch* branch, f32 lengthScale, f32 radiusScale, s32 level, SMeshBuffer* buffer, core::array<STreeLeaf>& leaves )
{
    if ( level <= 0 )
        return; // Do nothing, this branch is invisible.
    
    // Add this branch
    f32 length = lengthScale * getFloatFromValueRange( branch->Length, Seed++ );
    
    f32 radius = getFloatFromValueRange( branch->Radius, Seed++ );
    
    f32 radiusEndScale = radiusScale * getFloatFromValueRange( branch->RadiusEnd, Seed++ );
    
    f32 radiusEnd = radius * radiusEndScale;
    
    radius = radiusScale * radius;
    
    if ( level == 1 )
        radiusEnd = 0;
    
    s32 radialSegments = (level*(RadialSegments-3))/Levels + 3;
    
    if ( level > CutoffLevel )
    {
        BuildCylinder(
            buffer->Vertices,
            buffer->Indices,
            buffer->BoundingBox,
            
            length,
            radius,
            radiusEnd,
            radialSegments,
            
            transform );
    }
    
    // Add children
    if ( level > 1 )
    {
        core::list<SBranchChild>::Iterator it = branch->Children.begin();
        while ( it != branch->Children.end() )
        {
            SBranchChild* child = &(*it);
            
            it++;
            
            SBranch* childBranch = getBranchWithId( child->IdRef );
            
            if ( childBranch == 0 )
                continue;
            
            if ( !isValueInRange( level, child->LevelRange ) )
                continue;
            
            s32 childLevel = level + getIntFromValueRange( child->RelativeLevel, Seed++ ); // RelativeLevel is usually negative, -1 in particular.
            
            s32 numChildren = getIntFromValueRange( child->Count, Seed++ );
            
            f32 positionRange = child->Position.Max - child->Position.Min;
            
            positionRange /= (f32)numChildren;
            
            f32 orientation = getRandomFloat( Seed++, 0, 360.0f );
            
            for ( s32 i=0; i<numChildren; i++ )
            {
                f32 childLengthScale = lengthScale * getFloatFromValueRange( child->LengthScale, Seed++ );
                
                orientation += getFloatFromValueRange( child->Orientation, Seed++ );
                
                // Clamp value between 0 and 360. This is needed for gravity to work properly
                if ( orientation < 0.0f )
                    orientation += 360.0f;
                else
                if ( orientation > 360.0f )
                    orientation -= 360.0f;
                
                f32 childOrientation = orientation;
                
                f32 gravity = getFloatFromValueRange( child->GravityInfluence, Seed++ );
                
                f32 childPitch = getFloatFromValueRange( child->Pitch, Seed++ );
                
                f32 childPosition = getFloatFromValueRange( child->Position, Seed++ );
                
                f32 position;
                
                if ( child->Position.IsValue )
                    position = child->Position.Value;
                else
                    position = (child->Position.Min + positionRange * i + positionRange * getRandomFloat( Seed++, 0, 1 ));
                
                f32 childRadiusScale = (radiusScale*(1.0f-position) + radiusEndScale*position) * getFloatFromValueRange( child->RadiusScale, Seed++ );
                
                // Build transformation matrix
                core::matrix4 mat;
                
                mat.setRotationDegrees( core::vector3df(childPitch, childOrientation, 0.0f) );
                
                mat[13] = length * position;
                
                mat = transform * mat;
                
                
                if ( gravity != 0.0f )
                {
                    // Do some extra work
                    
                    core::vector3df vDown = core::vector3df( 0, -1, 0 );
                    
                    core::vector3df vBranch = core::vector3df( 0, 1, 0 );
                    mat.rotateVect(vBranch);
                    
                    core::vector3df vSide;
                    
                    if ( fabs( vBranch.Y ) >= 0.9f )
                    {
                        vSide = core::vector3df( 1, 0, 0 );
                        mat.rotateVect(vSide);
                    }
                    else
                    {
                        vSide = vBranch.crossProduct(vDown);
                        vSide.normalize();
                    }
                    
                    vDown = vSide.crossProduct(vBranch);
                    vDown.normalize();
                    
                    setMatrixVec( mat, 0, vSide );
                    setMatrixVec( mat, 2, vDown );
                    
                    f32 dot = -vBranch.Y;
                    
                    if ( gravity < 0.0f )
                        dot = -dot;
                    
                    f32 angle = acos( dot );
                    
                    angle *= gravity;
                    
                    core::matrix4 mat2;
                    mat2.setRotationRadians( core::vector3df( angle,0,0 ) );
                    
                    mat = mat * mat2;
                }
                
                // Add the branch
                appendBranch( mat, childBranch, childLengthScale, childRadiusScale, childLevel, buffer, leaves );
            }
        }
    }
    
    // Add leaves
    if ( AddLeaves )
    {
        core::list<SLeaf>::Iterator lit = branch->Leaves.begin();
        while ( lit != branch->Leaves.end() )
        {
            SLeaf* leaf = &(*lit);
            lit++;
            
            if ( !isValueInRange( level, leaf->LevelRange ) )
                continue;
            
            s32 count = getIntFromValueRange( leaf->Count, LeafSeed++ );
            
            for ( s32 i=0; i<count; i++ )
            {
            
                f32 width = getFloatFromValueRange( leaf->Width, LeafSeed++ );
                f32 height = getFloatFromValueRange( leaf->Height, LeafSeed++ );
                f32 scale = getFloatFromValueRange( leaf->Scale, LeafSeed++ );
                f32 position = getFloatFromValueRange( leaf->Position, LeafSeed++ );
                f32 roll = getFloatFromValueRange( leaf->Roll, LeafSeed++ );
                f32 anchor = getFloatFromValueRange( leaf->Anchor, LeafSeed++ );
                
                core::matrix4 mat;
                
                mat[13] = length * position;
                
                mat = transform * mat;
                
                STreeLeaf treeLeaf;
                
                treeLeaf.Position = mat.getTranslation();
                
                treeLeaf.Color.setRed( getIntFromValueRange( leaf->Red, LeafSeed++ ) );
                treeLeaf.Color.setGreen( getIntFromValueRange( leaf->Green, LeafSeed++ ) );
                treeLeaf.Color.setBlue( getIntFromValueRange( leaf->Blue, LeafSeed++ ) );
                treeLeaf.Color.setAlpha( getIntFromValueRange( leaf->Alpha, LeafSeed++ ) );
                
                treeLeaf.Size = core::dimension2df(scale*width, scale*height);
                treeLeaf.Roll = roll;
                
                if ( leaf->HasAxis )
                {
                    treeLeaf.HasAxis = true;
                    treeLeaf.Axis = leaf->Axis;
                    treeLeaf.Position += leaf->Axis * height * scale * anchor / 2.0f;
                }
                else
                {
                    treeLeaf.HasAxis = false;
                }
                
                leaves.push_back( treeLeaf );
            }
            
        }
    }
}
Exemplo n.º 18
0
/**
* CParticleEffect::initParticle
* @date Modified June 01, 2006
*/
void CParticleEffect::initParticle(CParticleManager::SParticle* pParticle, D3DXMATRIX* mOffset)
{
	D3DXMATRIX mPosOffset, mOrientation = *mOffset;
	D3DXMatrixIdentity(&mPosOffset);
	mPosOffset._41 = mOffset->_41;
	mPosOffset._42 = mOffset->_42;
	mPosOffset._43 = mOffset->_43;
	mOrientation._41 = mOrientation._42 = mOrientation._43 = 0.0f;
	mOrientation._44 = 1.0f;

	float fMinVel, fMaxVel;
	D3DXVec3Normalize(&fMinVel, &m_vMinVelocity, &m_vMinVelocity);
	D3DXVec3Normalize(&fMaxVel, &m_vMaxVelocity, &m_vMaxVelocity);

	D3DXVec3TransformCoord(&m_vMinVelocityTrans, &m_vMinVelocity, &mOrientation);
	D3DXVec3TransformCoord(&m_vMaxVelocityTrans, &m_vMaxVelocity, &mOrientation);

	m_vMinVelocity *= fMinVel;
	m_vMaxVelocity *= fMaxVel;

	// Update attributes
	BYTE cR = GET_RED(pParticle->Color), 
		 cG = GET_GREEN(pParticle->Color), 
		 cB = GET_BLUE(pParticle->Color), 
		 cA = GET_ALPHA(pParticle->Color);
	for(size_t j = 0; j < m_vAttributes.size(); ++j)
	{
		float fScale = m_vAttributes[j]->getValue(0.0f);
		switch(m_vAttributes[j]->getType())
		{
		case CParticleAttribute::ATR_COLORRED: cR = (BYTE)(fScale * 255.0f); break;
		case CParticleAttribute::ATR_COLORGREEN: cG = (BYTE)(fScale * 255.0f); break;
		case CParticleAttribute::ATR_COLORBLUE: cB = (BYTE)(fScale * 255.0f); break;
		case CParticleAttribute::ATR_COLORALPHA: cA = (BYTE)(fScale * 255.0f); break;
		case CParticleAttribute::ATR_SIZE: pParticle->Size = fScale; break;
		case CParticleAttribute::ATR_ROTATION: pParticle->Rotation = degreesToRadians(fScale); break;
		case CParticleAttribute::ATR_ACCELX: pParticle->Acceleration.x = fScale; break;
		case CParticleAttribute::ATR_ACCELY: pParticle->Acceleration.y = fScale; break;
		case CParticleAttribute::ATR_ACCELZ: pParticle->Acceleration.z = fScale; break;
		}
	}
	pParticle->Color = D3DCOLOR_ARGB(cA, cR, cG, cB);
	getRandomVector(&pParticle->Velocity, &m_vMinVelocityTrans, &m_vMaxVelocityTrans);
	pParticle->Velocity *= getRandomFloat(fMinVel, fMaxVel);
	m_vMinVelocityTrans *= fMinVel;
	m_vMaxVelocityTrans *= fMaxVel;
	
	D3DXVECTOR3 vMin(0.0f, 0.0f, 0.0f), vMax(0.0f, 0.0f, 0.0f);
	switch(m_eSpawnShape)
	{
	case SH_CUBE:
		vMin.x = -m_vSpawnRadius.x;
		vMin.y = -m_vSpawnRadius.y;
		vMin.z = -m_vSpawnRadius.z;
		getRandomVector(&pParticle->Position, &vMin, &m_vSpawnRadius);
		break;
	case SH_SQUARE:
		vMin.x = -m_vSpawnRadius.x;
		vMin.z = -m_vSpawnRadius.z;
		vMax.x = m_vSpawnRadius.x;
		vMax.z = m_vSpawnRadius.z;
		getRandomVector(&pParticle->Position, &vMin, &vMax);
		break;
	case SH_SPHERE:
		getRandomVector(&vMin, -1.0f, 1.0f);
		D3DXVec3Normalize(&vMin, &vMin);
		pParticle->Position.x = vMin.x * m_vSpawnRadius.x;
		pParticle->Position.y = vMin.y * m_vSpawnRadius.x;
		pParticle->Position.z = vMin.z * m_vSpawnRadius.x;
		break;
	case SH_CIRCLE:
		getRandomVector(&vMin, -1.0f, 1.0f);
		D3DXVec3Normalize(&vMin, &vMin);
		pParticle->Position.x = vMin.x * m_vSpawnRadius.x;
		pParticle->Position.y = 0.0f;
		pParticle->Position.z = vMin.z * m_vSpawnRadius.x;
		break;
	}
	
	D3DXVec3TransformCoord(&pParticle->Position, &pParticle->Position, &mPosOffset);
}
Exemplo n.º 19
0
inline s32 getRandomInt( s32 seed, s32 min, s32 max )
{
    return (s32)(getRandomFloat(seed,min,max) + 0.50f);
}
Exemplo n.º 20
0
void _drawDynamicLight(light *lght) {
	int x, y, penalty, r_tint, g_tint, b_tint;
	float distMod, alpha;
	character *player = getPlayer();
	TCOD_map_t levelMap = getLevelMap();
	
	if (!lght->lightMap) {
		return;
	}
	
	TCOD_map_clear(lght->lightMap, 0, 0);
	
	if (!lght->fuel) {
		return;
	}
	
	for (y = lght->y - 32; y < lght->y + 32; y++) {
		for (x = lght->x - 32; x < lght->x + 32; x++) {
			if (x < 0 || x >= WINDOW_WIDTH || y < 0 || y >= WINDOW_HEIGHT) {
				continue;
			}
			
			if (TCOD_map_is_in_fov(lght->fov, x, y)) {
				if (lght->fuel < lght->size) {
					penalty = lght->size - lght->fuel;
				} else {
					penalty = 0;
				}
				
				distMod = lght->size - (distanceFloat(lght->x, lght->y, x, y) + penalty);
				
				if (distMod <= 0) {
					TCOD_map_set_properties(lght->lightMap, x, y, 0, 0);
				} else {
					TCOD_map_set_properties(lght->lightMap, x, y, 1, 1);
				}

				if (isPositionWalkable(x, y)) {
					distMod -= getRandomFloat(0, lght->flickerRate);
				}
				
				if (distMod < 0) {
					distMod = 0;
				} else if (distMod > lght->size / 2) {
					distMod = lght->size / 2;
				}
				
				alpha = (distMod / (float) lght->size);
				alpha *= lght->sizeMod;

				if (lght->noTint) {
					r_tint = 1;
					g_tint = 1;
					b_tint = 1;
				} else {
					if (!TCOD_map_is_walkable(levelMap, x, y)) {
						r_tint = 55 + RED_SHIFT;
						g_tint = 55;
						b_tint = 55;

						if (alpha > .45) {
							alpha = .45;
						}
					} else {
						r_tint = lght->r_tint + RED_SHIFT;
						g_tint = lght->g_tint;
						b_tint = lght->b_tint;

						alpha = clipFloat(alpha, 0, lght->brightness);
					}
				}
				
				if (!player || TCOD_map_is_in_fov(player->fov, x, y)) {
					drawCharBackEx(DYNAMIC_LIGHT_CONSOLE, x, y, TCOD_color_RGB(r_tint, g_tint, b_tint), TCOD_BKGND_ADDALPHA(alpha));
				}
			}
		}
	}
}
void FaultInjector::start(float tMin, float tMax) {
	timer.attach(this, &FaultInjector::generateFaults,
			getRandomFloat(tMin, tMax));
}