当前位置: 首页>>代码示例>>C++>>正文


C++ Animation类代码示例

本文整理汇总了C++中Animation的典型用法代码示例。如果您正苦于以下问题:C++ Animation类的具体用法?C++ Animation怎么用?C++ Animation使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Animation类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: xmlParts

	void Puppet::Save()
	{
		if (entity)
		{
			// save to filename
			TiXmlDocument xmlDoc;

			/// TextureAtlas
			if (textureAtlas)
			{
				textureAtlas->Save(&xmlDoc);
			}

			/// Parts
			//TiXmlElement *xmlParts = xmlDoc.FirstChildElement("Parts");
			TiXmlElement xmlParts("Parts");
			for (std::list<Part*>::iterator i = parts.begin(); i != parts.end(); ++i)
			{
				if ((*i)->GetParent() == entity)
				{
					printf("calling SaveParts... top level...\n");
					SavePart(&xmlParts, (*i));
				}
			}
			xmlDoc.InsertEndChild(xmlParts);


			/// Animations
			TiXmlElement xmlAnimations("Animations");
			{
				/// Animation
				for (std::list<Animation>::iterator i = animations.begin(); i != animations.end(); ++i)
				{
					TiXmlElement xmlAnimation("Animation");

					Animation *animation = &(*i);
                
					XMLFileNode xmlFileNodeKeyFrameAnim(&xmlAnimation);
					animation->Save(&xmlFileNodeKeyFrameAnim);

					/// PartKeyFrames
					for (std::list<Part*>::iterator j = parts.begin(); j != parts.end(); ++j)
					{
						PartKeyFrames *partKeyFrames = animation->GetPartKeyFrames(*j);
						if (partKeyFrames)
						{
							TiXmlElement xmlPartKeyFrames("PartKeyFrames");
							XMLFileNode xmlFileNodePartKeyFrames(&xmlPartKeyFrames);

							partKeyFrames->Save(&xmlFileNodePartKeyFrames);

							/// KeyFrame
					
							std::list<KeyFrame> *keyFrames = partKeyFrames->GetKeyFrames();
							for (std::list<KeyFrame>::iterator k = keyFrames->begin(); k != keyFrames->end(); ++k)
							{
								KeyFrame *keyFrame = &(*k);

								TiXmlElement xmlKeyFrame("KeyFrame");
								XMLFileNode xmlFileNodeKeyFrame(&xmlKeyFrame);

								keyFrame->Save(&xmlFileNodeKeyFrame);

								xmlPartKeyFrames.InsertEndChild(xmlKeyFrame);
							}

							xmlAnimation.InsertEndChild(xmlPartKeyFrames);
						}
					}

					xmlAnimations.InsertEndChild(xmlAnimation);
				}
			}
			xmlDoc.InsertEndChild(xmlAnimations);

			xmlDoc.SaveFile(Assets::GetContentPath() + filename);
		}
	}
开发者ID:amackworth,项目名称:Monocle-Engine,代码行数:78,代码来源:Puppet.cpp

示例2: animationAttached

void AnimationTimeline::animationAttached(Animation& animation)
{
    ASSERT(animation.timeline() == this);
    ASSERT(!m_animations.contains(&animation));
    m_animations.add(&animation);
}
开发者ID:alexanderbill,项目名称:blink-crosswalk,代码行数:6,代码来源:AnimationTimeline.cpp

示例3: reset

    //---------------------------------------------------------------------
    void Skeleton::setAnimationState(const AnimationStateSet& animSet)
    {
        /* 
        Algorithm:
          1. Reset all bone positions
          2. Iterate per AnimationState, if enabled get Animation and call Animation::apply
        */

        // Reset bones
        reset();

		Real weightFactor = 1.0f;
		if (mBlendState == ANIMBLEND_AVERAGE)
		{
			// Derive total weights so we can rebalance if > 1.0f
			Real totalWeights = 0.0f;
			ConstEnabledAnimationStateIterator stateIt = 
				animSet.getEnabledAnimationStateIterator();
			while (stateIt.hasMoreElements())
			{
				const AnimationState* animState = stateIt.getNext();
				// Make sure we have an anim to match implementation
				const LinkedSkeletonAnimationSource* linked = 0;
				if (_getAnimationImpl(animState->getAnimationName(), &linked))
				{
					totalWeights += animState->getWeight();
				}
			}

			// Allow < 1.0f, allows fade out of all anims if required 
			if (totalWeights > 1.0f)
			{
				weightFactor = 1.0f / totalWeights;
			}
		}

        // Per enabled animation state
        ConstEnabledAnimationStateIterator stateIt = 
            animSet.getEnabledAnimationStateIterator();
        while (stateIt.hasMoreElements())
        {
            const AnimationState* animState = stateIt.getNext();
            const LinkedSkeletonAnimationSource* linked = 0;
            Animation* anim = _getAnimationImpl(animState->getAnimationName(), &linked);
            // tolerate state entries for animations we're not aware of
            if (anim)
            {
              if(animState->hasBlendMask())
              {
                anim->apply(this, animState->getTimePosition(), animState->getWeight() * weightFactor,
                  animState->getBlendMask(), linked ? linked->scale : 1.0f);
              }
              else
              {
                anim->apply(this, animState->getTimePosition(), 
                  animState->getWeight() * weightFactor, linked ? linked->scale : 1.0f);
              }
            }
        }


    }
开发者ID:milram,项目名称:ogre-1.7.4-osx,代码行数:63,代码来源:OgreSkeleton.cpp

示例4: assert

Animation* AnimationTarget::createAnimation(const char* id, Properties* animationProperties)
{
    assert(animationProperties);
    assert(std::strcmp(animationProperties->getNamespace(), "animation") == 0);
    
    const char* propertyIdStr = animationProperties->getString("property");
    assert(propertyIdStr);
    
    // Get animation target property id
    int propertyId = AnimationTarget::getPropertyId(_targetType, propertyIdStr);
    assert(propertyId != -1);
    
    unsigned int keyCount = animationProperties->getInt("keyCount");
    assert(keyCount > 0);

    const char* keyTimesStr = animationProperties->getString("keyTimes");
    assert(keyTimesStr);
    
    const char* keyValuesStr = animationProperties->getString("keyValues");
    assert(keyValuesStr);
    
    const char* curveStr = animationProperties->getString("curve");
    assert(curveStr);
    
    char delimeter = ' ';
    unsigned int startOffset = 0;
    unsigned int endOffset = (unsigned int)std::string::npos;
    
    unsigned long* keyTimes = new unsigned long[keyCount];
    for (unsigned int i = 0; i < keyCount; i++)
    {
        endOffset = static_cast<std::string>(keyTimesStr).find_first_of(delimeter, startOffset);
        if (endOffset != std::string::npos)
        {
            keyTimes[i] = std::strtoul(static_cast<std::string>(keyTimesStr).substr(startOffset, endOffset - startOffset).c_str(), NULL, 0);
        }
        else
        {
            keyTimes[i] = std::strtoul(static_cast<std::string>(keyTimesStr).substr(startOffset, static_cast<std::string>(keyTimesStr).length()).c_str(), NULL, 0);
        }
        startOffset = endOffset + 1;
    }

    startOffset = 0;
    endOffset = (unsigned int)std::string::npos;
    
    int componentCount = getAnimationPropertyComponentCount(propertyId);
    assert(componentCount > 0);
    
    unsigned int components = keyCount * componentCount;
    
    float* keyValues = new float[components];
    for (unsigned int i = 0; i < components; i++)
    {
        endOffset = static_cast<std::string>(keyValuesStr).find_first_of(delimeter, startOffset);
        if (endOffset != std::string::npos)
        {   
            keyValues[i] = std::atof(static_cast<std::string>(keyValuesStr).substr(startOffset, endOffset - startOffset).c_str());
        }
        else
        {
            keyValues[i] = std::atof(static_cast<std::string>(keyValuesStr).substr(startOffset, static_cast<std::string>(keyValuesStr).length()).c_str());
        }
        startOffset = endOffset + 1;
    }

    const char* keyInStr = animationProperties->getString("keyIn");
    float* keyIn = NULL;
    if (keyInStr)
    {
        keyIn = new float[components];
        startOffset = 0;
        endOffset = (unsigned int)std::string::npos;
        for (unsigned int i = 0; i < components; i++)
        {
            endOffset = static_cast<std::string>(keyInStr).find_first_of(delimeter, startOffset);
            if (endOffset != std::string::npos)
            {   
                keyIn[i] = std::atof(static_cast<std::string>(keyInStr).substr(startOffset, endOffset - startOffset).c_str());
            }
            else
            {
                keyIn[i] = std::atof(static_cast<std::string>(keyInStr).substr(startOffset, static_cast<std::string>(keyInStr).length()).c_str());
            }
            startOffset = endOffset + 1;
        }
    }
    
    const char* keyOutStr = animationProperties->getString("keyOut");
    float* keyOut = NULL;
    if (keyOutStr)
    {   
        keyOut = new float[components];
        startOffset = 0;
        endOffset = (unsigned int)std::string::npos;
        for (unsigned int i = 0; i < components; i++)
        {
            endOffset = static_cast<std::string>(keyOutStr).find_first_of(delimeter, startOffset);
            if (endOffset != std::string::npos)
            {   
//.........这里部分代码省略.........
开发者ID:jsethi,项目名称:GamePlay,代码行数:101,代码来源:AnimationTarget.cpp

示例5: UtcDaliModelBuildAnimation01

int UtcDaliModelBuildAnimation01(void)
{
  TestApplication application;
  TestPlatformAbstraction& platform = application.GetPlatform();

  tet_infoline("Testing Dali::MeshActor::New()");

  Dali::ModelData modelData = BuildTreeModel();

  // Raise a request
  Model model = Model::New("Tree");

  application.SendNotification();
  application.Render();
  Integration::ResourceRequest* request = platform.GetRequest(); // Return modelData
  if(request)
  {
    platform.SetResourceLoaded(request->GetId(), request->GetType()->id, Integration::ResourcePointer(&(modelData.GetBaseObject())));
  }
  application.Render();
  application.SendNotification();

  Actor actor = ModelActorFactory::BuildActorTree(model, ""); // model should be loaded
  Stage::GetCurrent().Add(actor);

  DALI_TEST_CHECK(model.GetLoadingState() == ResourceLoadingSucceeded);
  DALI_TEST_CHECK(actor);
  DALI_TEST_CHECK(actor.GetName().compare("root") == 0);

  DALI_TEST_EQUALS(model.NumberOfAnimations(), static_cast<size_t>(1), TEST_LOCATION);
  unsigned int animIndex=0;
  bool found = model.FindAnimation("Anim1", animIndex);
  DALI_TEST_CHECK(found);

  Animation twigAnim = ModelActorFactory::BuildAnimation(model, actor, animIndex);
  DALI_TEST_CHECK(twigAnim);
  DALI_TEST_EQUALS(twigAnim.GetDuration(), 10.0f, 0.001, TEST_LOCATION);
  DALI_TEST_CHECK(twigAnim.GetDefaultAlphaFunction() == Dali::AlphaFunctions::Linear);

  Actor twigActor = actor.FindChildByName("twig");
  DALI_TEST_CHECK(twigActor);

  // Start the animation
  twigAnim.Play();

  float durationSeconds = 10.0f;

  bool signalReceived(false);
  AnimationFinishCheck finishCheck(signalReceived);
  twigAnim.FinishedSignal().Connect(&application, finishCheck);
  application.SendNotification();
  application.Render();
  finishCheck.CheckSignalNotReceived();
  DALI_TEST_EQUALS( twigActor.GetCurrentPosition(), Vector3(2.0f, 1.0f, 0.0f), 0.01f, TEST_LOCATION );

  application.Render(static_cast<unsigned int>(durationSeconds*250.0f)/* 25% progress */);
  application.SendNotification();
  DALI_TEST_EQUALS( twigActor.GetCurrentPosition(), Vector3(2.5f, 1.0f, 2.5f), 0.01f, TEST_LOCATION );

  application.Render(static_cast<unsigned int>(durationSeconds*500.0f)/* 75% progress */);
  application.SendNotification();
  DALI_TEST_EQUALS( twigActor.GetCurrentPosition(), Vector3(3.5f, 1.0f, 7.5f), 0.01f, TEST_LOCATION );

  application.Render(static_cast<unsigned int>(durationSeconds*500.0f)/* Past Finished */);
  application.SendNotification();
  DALI_TEST_EQUALS( twigActor.GetCurrentPosition(), Vector3(4.0f, 1.0f, 10.0f), 0.01f, TEST_LOCATION );

  finishCheck.CheckSignalReceived();
  END_TEST;
}
开发者ID:Tarnyko,项目名称:dali-core,代码行数:70,代码来源:utc-Dali-Model.cpp

示例6: mapAnimationTimingFunction

void CSSToStyleMap::mapAnimationTimingFunction(Animation& animation, const CSSValue& value)
{
    if (value.treatAsInitialValue(CSSPropertyWebkitAnimationTimingFunction)) {
        animation.setTimingFunction(Animation::initialTimingFunction());
        return;
    }

    if (is<CSSPrimitiveValue>(value)) {
        switch (downcast<CSSPrimitiveValue>(value).getValueID()) {
        case CSSValueLinear:
            animation.setTimingFunction(LinearTimingFunction::create());
            break;
        case CSSValueEase:
            animation.setTimingFunction(CubicBezierTimingFunction::create());
            break;
        case CSSValueEaseIn:
            animation.setTimingFunction(CubicBezierTimingFunction::create(CubicBezierTimingFunction::EaseIn));
            break;
        case CSSValueEaseOut:
            animation.setTimingFunction(CubicBezierTimingFunction::create(CubicBezierTimingFunction::EaseOut));
            break;
        case CSSValueEaseInOut:
            animation.setTimingFunction(CubicBezierTimingFunction::create(CubicBezierTimingFunction::EaseInOut));
            break;
        case CSSValueStepStart:
            animation.setTimingFunction(StepsTimingFunction::create(1, true));
            break;
        case CSSValueStepEnd:
            animation.setTimingFunction(StepsTimingFunction::create(1, false));
            break;
        default:
            break;
        }
        return;
    }

    if (is<CSSCubicBezierTimingFunctionValue>(value)) {
        auto& cubicTimingFunction = downcast<CSSCubicBezierTimingFunctionValue>(value);
        animation.setTimingFunction(CubicBezierTimingFunction::create(cubicTimingFunction.x1(), cubicTimingFunction.y1(), cubicTimingFunction.x2(), cubicTimingFunction.y2()));
    } else if (is<CSSStepsTimingFunctionValue>(value)) {
        auto& stepsTimingFunction = downcast<CSSStepsTimingFunctionValue>(value);
        animation.setTimingFunction(StepsTimingFunction::create(stepsTimingFunction.numberOfSteps(), stepsTimingFunction.stepAtStart()));
    } else if (is<CSSSpringTimingFunctionValue>(value)) {
        auto& springTimingFunction = downcast<CSSSpringTimingFunctionValue>(value);
        animation.setTimingFunction(SpringTimingFunction::create(springTimingFunction.mass(), springTimingFunction.stiffness(), springTimingFunction.damping(), springTimingFunction.initialVelocity()));
    }
}
开发者ID:caiolima,项目名称:webkit,代码行数:47,代码来源:CSSToStyleMap.cpp

示例7: project

void ChangeControllerState::undo() {
	Animation* a = project()->getAnimation(m_animation);
	a->setControllerState(m_controller, !m_state);
}
开发者ID:sgynn,项目名称:animtool,代码行数:4,代码来源:ikcommands.cpp

示例8: evaluateDLOA

// TODO: get the time it takes the user to draw the LOA, going to need the control points dropped at intervals
Animation* evaluateDLOA(ModelData* modelData, vector<struct pt*> spline) {
    Animation* animation = new Animation();
    ofstream myfile;
    myfile.open ("/home/psarahdactyl/Documents/ccfunfunfun.txt");
    spline.clear();
    for(int i = 0; i < 100; i+=1)
    {
        spline.push_back(createPoint(i, 0, 0));
    }

    // calculate the constant b
	double modelLength = getModelLength(modelData->mutable_model());
	double splineLength = getSplineLength(spline);
    myfile << "ml " << modelLength << endl;
    myfile << "sl " << splineLength << endl;
	double b = modelLength / (splineLength);
    myfile << "b " << b << endl;

    // calculate points in spline per frame
    double pointsPerFrame = spline.size() * b;
    myfile << "ss: " << spline.size() << endl;
    myfile << "ppf: " << pointsPerFrame << endl;

    // calculate which point goes with which joint
    Node* root = modelData->mutable_model();

    // maps points from user drawn curve -- now a spline -- to the joints in the model
	vector<int> correspondingPoints = mapPoints(root, pointsPerFrame, modelLength);
    for(int h = 0; h < correspondingPoints.size(); h++)
    {
        myfile << correspondingPoints.at(h) << endl;
    }

    vector<struct pt*> extra;

    struct pt* last = spline.at(spline.size()-1);
    struct pt* secondLast = spline.at(spline.size()-2);

    double x = last->x - secondLast->x;
    double y = last->y - secondLast->y;
    double z = last->z - secondLast->z;
    struct pt* difference = createPoint(x, y, z);

    for(double t = 1; t <= pointsPerFrame; t++)
    {
        struct pt* diff = multScalar(t, difference);
        struct pt* r = add(last, diff);
        extra.push_back(r);
    }

    vector<struct pt*> newSpline;
    newSpline.reserve( spline.size() + extra.size() ); // preallocate memory
    newSpline.insert( newSpline.end(), spline.begin(), spline.end() );
    newSpline.insert( newSpline.end(), extra.begin(), extra.end() );

    // go through every point in spline
    // iterating by 1 every time gives us frames overlapping points in the spline
    for (int i = 0; i < newSpline.size() - pointsPerFrame; i++) {
        int index = 0;
        // move model and its joints
        Node frame = jointsToSpline(root, newSpline, correspondingPoints, index,  &myfile);
	    frame.set_name(root->name());

        // go through the mapped joints on the model and move them up by 1
        // since we are on a new frame
        vector<int> newCorresponding;
        for (int j = 0; j < correspondingPoints.size(); j++) {
            newCorresponding.push_back(correspondingPoints.at(j)+1);
        }
        // copy for the next iteration 
        correspondingPoints = newCorresponding;

        // add frames to the animation
        Node* a = animation->add_frames();
        Node parent;
        Node* p = parent.add_children();
        parent.CopyFrom(frame);
        p->CopyFrom(frame);
        a->CopyFrom(parent);
	    a->set_name(root->name());
    }

    return animation;
}
开发者ID:swell-animations,项目名称:swell-animations-algorithm,代码行数:85,代码来源:AnimationGenerationRotationAttempt.cpp

示例9: writeAnimation

void LevelParser::writeAnimation(tinyxml2::XMLElement* pAnimElem, Animation animation)
{
	pAnimElem->SetAttribute("row", animation.getRow());				// Sprite sheet row
	pAnimElem->SetAttribute("nFrames", animation.getNFrames());		// Total frames
	pAnimElem->SetAttribute("frameTime", animation.getFrameTime());	// Interval between frames
}
开发者ID:afrosistema,项目名称:S2PEditor,代码行数:6,代码来源:LevelParser.cpp

示例10: Update

// Update: draw background
update_status ModuleBlinky::Update()
{
	Animation* current_animation = &idle;
	Animation* horitzontal = &a_hor;
	Animation* vertical = &a_vert;
	float position_x = position.x;
	float position_y = position.y;
	int i_position_x = position.x;
	int i_position_y = position.y;

	int tilepos_x = ((i_position_x + 16) / 16) * 16;
	int tilepos_y = ((i_position_y + 16) / 16) * 16;

	
	int d_up = 1000;
	int d_down = 1000;
	int d_right = 1000;
	int d_left = 1000;
	
	

	
	float speed = 1.5;

	if (SDL_GetTicks() - time <= 700){
		
			direction = 2;
		
			//if (SDL_GetTicks() - time >= 2000) direction = 1;
	}
	else if (SDL_GetTicks() - time <= 810){
		direction = 1;
	}
	else {
		if (turn == true){

			if (App->player->s_map[(tilepos_y / 16)][(tilepos_x / 16)] == -1 || App->player->s_map[(tilepos_y / 16)][(tilepos_x / 16)] == -2){
				if (App->player->s_map[(tilepos_y / 16) - 1][(tilepos_x / 16)] != 2){
					d_up = SDL_sqrt(((tilepos_x)-App->player->position.x)*(tilepos_x - App->player->position.x) + ((tilepos_y - 16) - App->player->position.y)*((tilepos_y - 16) - App->player->position.y));
				}

				if (App->player->s_map[(tilepos_y / 16) + 1][(tilepos_x / 16)] != 2){
					d_down = SDL_sqrt(((tilepos_x)-App->player->position.x)*(tilepos_x - App->player->position.x) + ((tilepos_y + 16) - App->player->position.y)*((tilepos_y + 16) - App->player->position.y));
				}

				if (App->player->s_map[(tilepos_y / 16)][(tilepos_x / 16) - 1] != 2){
					d_left = SDL_sqrt(((tilepos_x - 16) - App->player->position.x)*((tilepos_x - 16) - App->player->position.x) + ((tilepos_y)-App->player->position.y)*((tilepos_y)-App->player->position.y));
				}

				if (App->player->s_map[(tilepos_y / 16)][(tilepos_x / 16) + 1] != 2){
					d_right = SDL_sqrt(((tilepos_x + 16) - App->player->position.x)*((tilepos_x + 16) - App->player->position.x) + ((tilepos_y)-App->player->position.y)*((tilepos_y)-App->player->position.y));
				}

				if (direction == 0){
					d_left = 1000;
				}
				if (direction == 1){
					d_right = 1000;
				}
				if (direction == 2){
					d_down = 1000;
				}
				if (direction == 3){
					d_up = 1000;
				}


				if (d_up <= d_down && d_up <= d_right && d_up <= d_left){
					direction = 2; turn = false;
				}
				else if (d_right <= d_down && d_right <= d_left && d_right <= d_up){
					direction = 0; turn = false;
				}
				else if (d_down <= d_up && d_down <= d_right && d_down <= d_left){
					direction = 3; turn = false;
				}

				else if (d_left <= d_up && d_left <= d_right && d_left <= d_down){
					direction = 1; turn = false;
				}

			}
			if (App->player->power == true){

				d_up = 0;
				d_down = 0;
				d_right = 0;
				d_left = 0;

				if (App->player->s_map[(tilepos_y / 16)][(tilepos_x / 16)] == -1 || App->player->s_map[(tilepos_y / 16)][(tilepos_x / 16)] == -2){
					if (App->player->s_map[(tilepos_y / 16) - 1][(tilepos_x / 16)] != 2){
						d_up = SDL_sqrt(((tilepos_x)-App->player->position.x)*(tilepos_x - App->player->position.x) + ((tilepos_y - 16) - App->player->position.y)*((tilepos_y - 16) - App->player->position.y));
					}

					if (App->player->s_map[(tilepos_y / 16) + 1][(tilepos_x / 16)] != 2){
						d_down = SDL_sqrt(((tilepos_x)-App->player->position.x)*(tilepos_x - App->player->position.x) + ((tilepos_y + 16) - App->player->position.y)*((tilepos_y + 16) - App->player->position.y));
					}

					if (App->player->s_map[(tilepos_y / 16)][(tilepos_x / 16) - 1] != 2){
//.........这里部分代码省略.........
开发者ID:adrixdx,项目名称:ms-pacman,代码行数:101,代码来源:ModuleBlinky.cpp

示例11: Scene

void SkeletalAnimation::CreateScene()
{
    ResourceCache* cache = GetSubsystem<ResourceCache>();

    scene_ = new Scene(context_);

    // Create octree, use default volume (-1000, -1000, -1000) to (1000, 1000, 1000)
    // Also create a DebugRenderer component so that we can draw debug geometry
    scene_->CreateComponent<Octree>();
    scene_->CreateComponent<DebugRenderer>();

    // Create scene node & StaticModel component for showing a static plane
    Node* planeNode = scene_->CreateChild("Plane");
    planeNode->SetScale(Vector3(100.0f, 1.0f, 100.0f));
    StaticModel* planeObject = planeNode->CreateComponent<StaticModel>();
    planeObject->SetModel(cache->GetResource<Model>("Models/Plane.mdl"));
    planeObject->SetMaterial(cache->GetResource<Material>("Materials/StoneTiled.xml"));

    // Create a Zone component for ambient lighting & fog control
    Node* zoneNode = scene_->CreateChild("Zone");
    Zone* zone = zoneNode->CreateComponent<Zone>();
    zone->SetBoundingBox(BoundingBox(-1000.0f, 1000.0f));
    zone->SetAmbientColor(Color(0.15f, 0.15f, 0.15f));
    zone->SetFogColor(Color(0.5f, 0.5f, 0.7f));
    zone->SetFogStart(100.0f);
    zone->SetFogEnd(300.0f);

    // Create a directional light to the world. Enable cascaded shadows on it
    Node* lightNode = scene_->CreateChild("DirectionalLight");
    lightNode->SetDirection(Vector3(0.6f, -1.0f, 0.8f));
    Light* light = lightNode->CreateComponent<Light>();
    light->SetLightType(LIGHT_DIRECTIONAL);
    light->SetCastShadows(true);
    light->SetShadowBias(BiasParameters(0.00025f, 0.5f));
    // Set cascade splits at 10, 50 and 200 world units, fade shadows out at 80% of maximum shadow distance
    light->SetShadowCascade(CascadeParameters(10.0f, 50.0f, 200.0f, 0.0f, 0.8f));

    // Create animated models
    const unsigned NUM_MODELS = 100;
    const float MODEL_MOVE_SPEED = 2.0f;
    const float MODEL_ROTATE_SPEED = 100.0f;
    const BoundingBox bounds(Vector3(-47.0f, 0.0f, -47.0f), Vector3(47.0f, 0.0f, 47.0f));

    for (unsigned i = 0; i < NUM_MODELS; ++i)
    {
        Node* modelNode = scene_->CreateChild("Jack");
        modelNode->SetPosition(Vector3(Random(90.0f) - 45.0f, 0.0f, Random(90.0f) - 45.0f));
        modelNode->SetRotation(Quaternion(0.0f, Random(360.0f), 0.0f));
        AnimatedModel* modelObject = modelNode->CreateComponent<AnimatedModel>();
        modelObject->SetModel(cache->GetResource<Model>("Models/Jack.mdl"));
        modelObject->SetMaterial(cache->GetResource<Material>("Materials/Jack.xml"));
        modelObject->SetCastShadows(true);

        // Create an AnimationState for a walk animation. Its time position will need to be manually updated to advance the
        // animation, The alternative would be to use an AnimationController component which updates the animation automatically,
        // but we need to update the model's position manually in any case
        Animation* walkAnimation = cache->GetResource<Animation>("Models/Jack_Walk.ani");
        AnimationState* state = modelObject->AddAnimationState(walkAnimation);
        // The state would fail to create (return null) if the animation was not found
        if (state)
        {
            // Enable full blending weight and looping
            state->SetWeight(1.0f);
            state->SetLooped(true);
            state->SetTime(Random(walkAnimation->GetLength()));
        }

        // Create our custom Mover component that will move & animate the model during each frame's update
        Mover* mover = modelNode->CreateComponent<Mover>();
        mover->SetParameters(MODEL_MOVE_SPEED, MODEL_ROTATE_SPEED, bounds);
    }

    // Create the camera. Limit far clip distance to match the fog
    cameraNode_ = scene_->CreateChild("Camera");
    Camera* camera = cameraNode_->CreateComponent<Camera>();
    camera->SetFarClip(300.0f);

    // Set an initial position for the camera scene node above the plane
    cameraNode_->SetPosition(Vector3(0.0f, 5.0f, 0.0f));
}
开发者ID:FeodorFitsner,项目名称:Urho3D,代码行数:80,代码来源:SkeletalAnimation.cpp

示例12: xmlDoc

	void Puppet::Load(const std::string &filename, Entity *entity)
	{
		this->entity = entity;
		this->filename = filename;
		animations.clear();
		// delete parts?
		parts.clear();
		
		TiXmlDocument xmlDoc(Assets::GetContentPath() + filename);
		
		if (xmlDoc.LoadFile())
		{
			/// TextureAtlas
			TiXmlElement *xmlTextureAtlas = xmlDoc.FirstChildElement("TextureAtlas");
			if (xmlTextureAtlas)
			{
				textureAtlas = new TextureAtlas();
				textureAtlas->Load(xmlTextureAtlas);
			}
			
			/// Parts
			TiXmlElement *xmlParts = xmlDoc.FirstChildElement("Parts");
			if (xmlParts)
			{
				LoadParts(xmlParts, NULL);
			}

			/// Animations
			TiXmlElement *xmlAnimations = xmlDoc.FirstChildElement("Animations");
			if (xmlAnimations)
			{
				/// Animation
				TiXmlElement *xmlAnimation = xmlAnimations->FirstChildElement("Animation");
				while (xmlAnimation)
				{
					Animation animation;
                    XMLFileNode xmlFileNodeKeyFrameAnim(xmlAnimation);
					animation.Load(&xmlFileNodeKeyFrameAnim);

					/// PartKeyFrames
					TiXmlElement *xmlPartKeyFrames = xmlAnimation->FirstChildElement("PartKeyFrames");
					while (xmlPartKeyFrames)
					{
						PartKeyFrames partKeyFrames;
						partKeyFrames.SetPuppet(this);
                        XMLFileNode xmlFileNodeKeyFramePart(xmlPartKeyFrames);
						partKeyFrames.Load(&xmlFileNodeKeyFramePart);

						/// KeyFrame
						TiXmlElement *xmlKeyFrame = xmlPartKeyFrames->FirstChildElement("KeyFrame");
						while (xmlKeyFrame)
						{
							KeyFrame keyFrame;
                            XMLFileNode xmlFileNodeKeyFrame(xmlKeyFrame);
							keyFrame.Load(&xmlFileNodeKeyFrame);
							partKeyFrames.AddKeyFrame(keyFrame);

							xmlKeyFrame = xmlKeyFrame->NextSiblingElement("KeyFrame");
						}

						animation.AddPartKeyFrames(partKeyFrames);

						xmlPartKeyFrames = xmlPartKeyFrames->NextSiblingElement("PartKeyFrames");
					}

					animation.RefreshDuration();
					animations.push_back(animation);

					xmlAnimation = xmlAnimation->NextSiblingElement("Animation");
				}
			}
		}
		else
		{
			Debug::Log("Warning: Could not open puppet file: " + Assets::GetContentPath() + filename);
			Debug::Log("         " + std::string(xmlDoc.ErrorDesc()));
			printf("         Row: %d\n", xmlDoc.ErrorRow());
		}
	}
开发者ID:amackworth,项目名称:Monocle-Engine,代码行数:79,代码来源:Puppet.cpp

示例13: makeSpriteDirection

void SpriteDef::loadAnimation(xmlNodePtr animationNode,
                              Action *action, ImageSet *imageSet,
                              int variant_offset)
{
    const std::string directionName =
        XML::getProperty(animationNode, "direction", "");
    const SpriteDirection directionType = makeSpriteDirection(directionName);

    if (directionType == DIRECTION_INVALID)
    {
        logger->log("Warning: Unknown direction \"%s\" used in %s",
                directionName.c_str(), getIdPath().c_str());
        return;
    }

    Animation *animation = new Animation;
    action->setAnimation(directionType, animation);

    // Get animation frames
    for_each_xml_child_node(frameNode, animationNode)
    {
        const int delay = XML::getProperty(frameNode, "delay",
                                           DEFAULT_FRAME_DELAY);
        int offsetX = XML::getProperty(frameNode, "offsetX", 0) +
                imageSet->getOffsetX();
        int offsetY = XML::getProperty(frameNode, "offsetY", 0) +
                imageSet->getOffsetY();

        if (xmlStrEqual(frameNode->name, BAD_CAST "frame"))
        {
            const int index = XML::getProperty(frameNode, "index", -1);

            if (index < 0)
            {
                logger->log("No valid value for 'index'");
                continue;
            }

            Image *img = imageSet->get(index + variant_offset);

            if (!img)
            {
                logger->log("No image at index %d", index + variant_offset);
                continue;
            }

            animation->addFrame(img, delay, offsetX, offsetY);
        }
        else if (xmlStrEqual(frameNode->name, BAD_CAST "sequence"))
        {
            int start = XML::getProperty(frameNode, "start", -1);
            const int end = XML::getProperty(frameNode, "end", -1);

            if (start < 0 || end < 0)
            {
                logger->log("No valid value for 'start' or 'end'");
                continue;
            }

            while (end >= start)
            {
                Image *img = imageSet->get(start + variant_offset);

                if (!img)
                {
                    logger->log("No image at index %d", start + variant_offset);
                    break;
                }

                animation->addFrame(img, delay, offsetX, offsetY);
                start++;
            }
        }
        else if (xmlStrEqual(frameNode->name, BAD_CAST "end"))
        {
            animation->addTerminator();
        }
    } // for frameNode
}
开发者ID:TonyRice,项目名称:mana,代码行数:79,代码来源:spritedef.cpp

示例14: getBorder


//.........这里部分代码省略.........

    // Calculate total width and height.
    float totalWidth = 0;
    float totalHeight = 0;
    std::vector<Control*> controls = getControls();
    unsigned int controlsCount = controls.size();
    for (unsigned int i = 0; i < controlsCount; i++)
    {
        Control* control = controls.at(i);

        const Rectangle& bounds = control->getBounds();
        const Theme::Margin& margin = control->getMargin();

        float newWidth = bounds.x + bounds.width;
        if (newWidth > totalWidth)
        {
            totalWidth = newWidth;
        }

        float newHeight = bounds.y + bounds.height;
        if (newHeight > totalHeight)
        {
            totalHeight = newHeight;
        }
    }

    float vWidth = getImageRegion("verticalScrollBar", _state).width;
    float hHeight = getImageRegion("horizontalScrollBar", _state).height;
    float clipWidth = _bounds.width - containerBorder.left - containerBorder.right - containerPadding.left - containerPadding.right - vWidth;
    float clipHeight = _bounds.height - containerBorder.top - containerBorder.bottom - containerPadding.top - containerPadding.bottom - hHeight;

    // Apply and dampen inertia.
    if (!_scrolling && !_scrollingVelocity.isZero())
    {
        // Calculate the time passed since last update.
        float elapsedSecs = (float)elapsedTime * 0.001f;

        _scrollPosition.x += _scrollingVelocity.x * elapsedSecs;
        _scrollPosition.y += _scrollingVelocity.y * elapsedSecs;

        float dampening = 1.0f - _scrollingFriction * SCROLL_FRICTION_FACTOR * elapsedSecs;
        _scrollingVelocity.x *= dampening;
        _scrollingVelocity.y *= dampening;

        if (fabs(_scrollingVelocity.x) < 100.0f)
            _scrollingVelocity.x = 0.0f;
        if (fabs(_scrollingVelocity.y) < 100.0f)
            _scrollingVelocity.y = 0.0f;
    }

    // Stop scrolling when the far edge is reached.
    if (-_scrollPosition.x > totalWidth - clipWidth)
    {
        _scrollPosition.x = -(totalWidth - clipWidth);
        _scrollingVelocity.x = 0;
    }
    
    if (-_scrollPosition.y > totalHeight - clipHeight)
    {
        _scrollPosition.y = -(totalHeight - clipHeight);
        _scrollingVelocity.y = 0;
    }

    if (_scrollPosition.x > 0)
    {
        _scrollPosition.x = 0;
        _scrollingVelocity.x = 0;
    }

    if (_scrollPosition.y > 0)
    {
        _scrollPosition.y = 0;
        _scrollingVelocity.y = 0;
    }

    float scrollWidth = 0;
    if (clipWidth < totalWidth)
        scrollWidth = (clipWidth / totalWidth) * clipWidth;

    float scrollHeight = 0;
    if (clipHeight < totalHeight)
        scrollHeight = (clipHeight / totalHeight) * clipHeight;

    _scrollBarBounds.set(((-_scrollPosition.x) / totalWidth) * clipWidth,
                         ((-_scrollPosition.y) / totalHeight) * clipHeight,
                         scrollWidth, scrollHeight);

    // If scroll velocity is 0 and scrollbars are not always visible, trigger fade-out animation.
    if (!_scrolling && _scrollingVelocity.isZero() && _scrollBarsAutoHide && _scrollBarOpacity == 1.0f)
    {
        float to = 0;
        _scrollBarOpacity = 0.99f;
        Animation* animation = createAnimationFromTo("scrollbar-fade-out", ANIMATE_OPACITY, &_scrollBarOpacity, &to, Curve::QUADRATIC_IN_OUT, 500L);
        _scrollBarOpacityClip = animation->getClip();
        _scrollBarOpacityClip->play();
    }

    // Position controls within scroll area.
    _layout->update(this, _scrollPosition);
}
开发者ID:BernardsRegards,项目名称:GamePlay,代码行数:101,代码来源:Container.cpp

示例15: startImage

void ManhattanStyle::drawPrimitive(PrimitiveElement element, const QStyleOption *option,
                                   QPainter *painter, const QWidget *widget) const
{
    if (!panelWidget(widget))
        return QProxyStyle::drawPrimitive(element, option, painter, widget);

    bool animating = (option->state & State_Animating);
    int state = option->state;
    QRect rect = option->rect;
    QRect oldRect;
    QRect newRect;
    if (widget && (element == PE_PanelButtonTool) && !animating) {
        QWidget *w = const_cast<QWidget *> (widget);
        int oldState = w->property("_q_stylestate").toInt();
        oldRect = w->property("_q_stylerect").toRect();
        newRect = w->rect();
        w->setProperty("_q_stylestate", (int)option->state);
        w->setProperty("_q_stylerect", w->rect());

        // Determine the animated transition
        bool doTransition = ((state & State_On)         != (oldState & State_On)     ||
                             (state & State_MouseOver)  != (oldState & State_MouseOver));
        if (oldRect != newRect)
        {
            doTransition = false;
            d->animator.stopAnimation(widget);
        }

        if (doTransition) {
            QImage startImage(option->rect.size(), QImage::Format_ARGB32_Premultiplied);
            QImage endImage(option->rect.size(), QImage::Format_ARGB32_Premultiplied);
            Animation *anim = d->animator.widgetAnimation(widget);
            QStyleOption opt = *option;
            opt.state = (QStyle::State)oldState;
            opt.state |= State_Animating;
            startImage.fill(0);
            Transition *t = new Transition;
            t->setWidget(w);
            QPainter startPainter(&startImage);
            if (!anim) {
                drawPrimitive(element, &opt, &startPainter, widget);
            } else {
                anim->paint(&startPainter, &opt);
                d->animator.stopAnimation(widget);
            }
            QStyleOption endOpt = *option;
            endOpt.state |= State_Animating;
            t->setStartImage(startImage);
            d->animator.startAnimation(t);
            endImage.fill(0);
            QPainter endPainter(&endImage);
            drawPrimitive(element, &endOpt, &endPainter, widget);
            t->setEndImage(endImage);
            if (oldState & State_MouseOver)
                t->setDuration(150);
            else
                t->setDuration(75);
            t->setStartTime(QTime::currentTime());
        }
    }

    switch (element) {
    case PE_IndicatorDockWidgetResizeHandle:
        painter->fillRect(option->rect, Utils::StyleHelper::borderColor());
        break;
    case PE_FrameDockWidget:
        QCommonStyle::drawPrimitive(element, option, painter, widget);
        break;
    case PE_PanelLineEdit:
        {
            painter->save();

            // Fill the line edit background
            QRect filledRect = option->rect.adjusted(1, 1, -1, -1);
            painter->setBrushOrigin(filledRect.topLeft());
            painter->fillRect(filledRect, option->palette.base());

            if (option->state & State_Enabled)
                Utils::StyleHelper::drawCornerImage(d->lineeditImage, painter, option->rect, 5, 5, 5, 5);
            else
                Utils::StyleHelper::drawCornerImage(d->lineeditImage_disabled, painter, option->rect, 5, 5, 5, 5);

            if (option->state & State_HasFocus || option->state & State_MouseOver) {
                QColor hover = Utils::StyleHelper::baseColor();
                if (state & State_HasFocus)
                    hover.setAlpha(100);
                else
                    hover.setAlpha(50);

                painter->setPen(QPen(hover, 1));
                painter->drawRect(option->rect.adjusted(1, 1, -2 ,-2));
            }
            painter->restore();
        }
        break;

    case PE_FrameStatusBarItem:
        break;

    case PE_PanelButtonTool: {
//.........这里部分代码省略.........
开发者ID:EATtomatoes,项目名称:TauLabs,代码行数:101,代码来源:manhattanstyle.cpp


注:本文中的Animation类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。