void MouseUp()
    {
        if( g_app->m_location )
        {
	        Vector3 rayStart;
	        Vector3 rayDir;
	        g_app->m_camera->GetClickRay(g_app->m_renderer->ScreenW()/2, 
									     g_app->m_renderer->ScreenH()/2, &rayStart, &rayDir);
            Vector3 _pos;
            g_app->m_location->m_landscape.RayHit( rayStart, rayDir, &_pos );

            for( int i = 0; i < 10; ++i )
            {
                Vector3 spiritPos = _pos + Vector3( SFRAND(20.0), 0.0, SFRAND(20.0) );
                g_app->m_location->SpawnSpirit( spiritPos, g_zeroVector, 2, WorldObjectId() );
            }
        }
    }
예제 #2
0
파일: tile.cpp 프로젝트: Bercon/BerconMaps
// left up right down
void Tile::uvMapping(TilePoint& tp, Point3 p, float edges[4], TileParam& t, int dir) {
	float w = edges[2] - edges[0];
	float h = edges[1] - edges[3];
		
	// Center uvw
	Point3 uvw;
	uvw.x = p.x - edges[0] - w * .5f;
	uvw.y = p.y - edges[3] - h * .5f;
	uvw.z = p.z;

	// Prime randomness
	srand(tp.id*(tp.id*tp.id*15731 + 789221));

	// Angle
	float angle = getAngle(t.rotUV, t.randRot);

	// Random scale
	float scaleX, scaleY;	
	switch (t.autoScale) {
		case 1: { // UV
			scaleX = w; scaleY = h;
			break; }		
		case 2: { // UV Fit
			scaleX = w; scaleY = h; // Same as UV, but with additiona scaling below
			break; }
		case 3: { // UV Fit Keep aspect
			float s = MAX(w, h);		
			scaleX = s; scaleY = s;
			break; }
		case 4: { // UV Norm.
			scaleX = t.tileMaxWidth;
			scaleY = t.tileMaxHeight;
			break; }
		case 5: { // UV Norm. Keep aspect
			float s = MAX(t.tileMaxWidth, t.tileMaxHeight);		
			scaleX = s;
			scaleY = s;
			break; }		
	}

	// Calculate scaling required to fit UVs tightly around the tile
	if ((t.autoScale == 2 || t.autoScale == 3) && t.rotUV) { // Scale based on rotation so whole tile stays inside 0..1 space
		float scale = 2.f * SQRTHALF * cos(fmod(angle > 0 ? -angle : angle, HALFPI) + QUATPI);
		scaleX *= scale;
		scaleY *= scale;
	}	

	// Apply auto scale
	if (t.autoScale) {
		uvw.x /= scaleX;
		uvw.y /= scaleY;
	}

	// Flip
	if (t.flipX) if (rand() % 2) uvw.x = -uvw.x;
	if (t.flipY) if (rand() % 2) uvw.y = -uvw.y;
	
	// Random scale
	if (t.randScale) {
		if (t.lock) {
			float s = 1.f + SFRAND() * t.randSX;
			scaleX = s;
			scaleY = s;
		} else {
			scaleX = 1.f + SFRAND() * t.randSX;
			scaleY = 1.f + SFRAND() * t.randSY;
		}

		if (scaleX < 0) scaleX = 0.f;
		if (scaleY < 0) scaleY = 0.f;

		uvw.x /= scaleX;	 
		uvw.y /= scaleY;
	}

	// Offset
	if (t.randOffset) {
		uvw.x += UFRAND() * t.randX;
		uvw.y += UFRAND() * t.randY;
	}

	// Rotate
	if (t.rotUV)
		rotatePoint2(uvw, angle);

	// Offset to 0..1
	if (t.autoScale) {
		uvw.x += .5f;
		uvw.y += .5f;
	}

	// Return
	tp.uvw = uvw;
}
bool Bridge::UpdateEntityInTransit( Entity *_entity )
{
    Building *building = g_app->m_location->GetBuilding( m_nextBridgeId );    
    Bridge *nextBridge = (Bridge *) building;

    WorldObjectId id( _entity->m_id );
    
    if( m_status > 0.0 &&
        nextBridge && 
        nextBridge->m_type == Building::TypeBridge &&
        nextBridge->m_status > 0.0 )
    {
        Matrix34 theirMat(nextBridge->m_front, g_upVector, nextBridge->m_pos);
        Matrix34 theirSignal = nextBridge->m_signal->GetWorldMatrix(theirMat);
        Vector3 offset = (theirSignal.pos - _entity->m_pos).Normalise();
        double dist = ( _entity->m_pos - theirSignal.pos ).Mag();
        bool arrived = false;

        _entity->m_vel = offset * BRIDGE_TRANSPORTSPEED;
        if( _entity->m_vel.Mag() * SERVER_ADVANCE_PERIOD > dist )
        {
            _entity->m_vel = ( _entity->m_pos - theirSignal.pos ) / SERVER_ADVANCE_PERIOD;
            arrived = true;
        }

        _entity->m_pos += _entity->m_vel * SERVER_ADVANCE_PERIOD;
        _entity->m_onGround = false;
        _entity->m_enabled = false;

        
        if( arrived )
        {
            // We are there
            if( nextBridge->m_bridgeType == Bridge::BridgeTypeEnd )
            {
                Vector3 exitPos, exitFront;
                nextBridge->GetExit( exitPos, exitFront );
                _entity->m_pos = exitPos;
                _entity->m_front = exitFront;
                _entity->m_enabled = true;
                _entity->m_onGround = true;
                _entity->m_vel.Zero();

                g_app->m_location->m_entityGrid->AddObject( id, _entity->m_pos.x, _entity->m_pos.z, _entity->m_radius );
                return true;                
            }
            else if( nextBridge->m_bridgeType == Bridge::BridgeTypeTower )
            {
                nextBridge->EnterTeleport( id, true );
                return true;
            }
        }
                
        return false;
    }
    else
    {
        // Shit - we lost the carrier signal, so we die
        _entity->ChangeHealth( -500 );
        _entity->m_enabled = true;        
        _entity->m_vel = Vector3(SFRAND(10.0), FRAND(10.0), SFRAND(10.0) );

        g_app->m_location->m_entityGrid->AddObject( id, _entity->m_pos.x, _entity->m_pos.z, _entity->m_radius );
        return true;
    }
}