Пример #1
0
	MorphAnimation::MorphAnimation(ID3D10Device* device, const std::vector<std::string>& keyFrameFilenames,
								   const std::vector<float> timeSpans, const std::string& glowMap)
		: mTime(0.0f)
		, mDevice(device)
		, mCurrentFrame(0)
		, mLooping(true)
		, mForwards(true)
		, mEffect(device, "Resources/Effects/Morph.fx")
	{
		assert(keyFrameFilenames.size() == timeSpans.size());
		for (int i = 0; i < keyFrameFilenames.size(); ++i)
		{
			//mKeyFrames.push_back(KeyFrame(Resources::ModelResourceManager::Instance().Load(keyFrameFilenames[i]), timeSpans[i]));
			mKeyFrames.push_back(KeyFrame(new Resources::StaticModelData(mDevice, keyFrameFilenames[i]), timeSpans[i]));
		}

		Framework::Effect::InputLayoutVector vec;
		vec.push_back(Framework::Effect::InputLayoutElement("POSITION", DXGI_FORMAT_R32G32B32_FLOAT, 0, 0));
		vec.push_back(Framework::Effect::InputLayoutElement("NORMAL", DXGI_FORMAT_R32G32B32_FLOAT, 0, 0));
		vec.push_back(Framework::Effect::InputLayoutElement("TEXCOORD", DXGI_FORMAT_R32G32_FLOAT, 0, 0));
		vec.push_back(Framework::Effect::InputLayoutElement("POSITION", DXGI_FORMAT_R32G32B32_FLOAT, 1, 1));
		vec.push_back(Framework::Effect::InputLayoutElement("NORMAL", DXGI_FORMAT_R32G32B32_FLOAT, 1, 1));
		vec.push_back(Framework::Effect::InputLayoutElement("TEXCOORD", DXGI_FORMAT_R32G32_FLOAT, 1, 1));

		mEffect.GetTechniqueByIndex(0).GetPassByIndex(0).SetInputLayout(vec);
		mEffect.SetVariable("t", 0.0f);
		mEffect.SetVariable("gTexture", mKeyFrames[0].Data->MaterialData->GetMaterial(mKeyFrames[0].Data->MaterialName)->MainTexture->GetShaderResourceView());
		mEffect.SetVariable("gGlowMap", Resources::Texture(mDevice, glowMap).GetShaderResourceView());
		mEffect.SetVariable("Ka", mKeyFrames[0].Data->MaterialData->GetMaterial(mKeyFrames[0].Data->MaterialName)->Ambient.x);
		mEffect.SetVariable("Kd", mKeyFrames[0].Data->MaterialData->GetMaterial(mKeyFrames[0].Data->MaterialName)->Diffuse.x);
		mEffect.SetVariable("Ks", mKeyFrames[0].Data->MaterialData->GetMaterial(mKeyFrames[0].Data->MaterialName)->Specular.x);
		mEffect.SetVariable("A", mKeyFrames[0].Data->MaterialData->GetMaterial(mKeyFrames[0].Data->MaterialName)->SpecularExp);
	}
Пример #2
0
MorphAnimation::MorphAnimation(ID3D10Device* device, const std::vector<std::string>& keyFrameFilenames,
                               const std::vector<float> timeSpans)
    : mTime(0.0f)
    , mDevice(device)
    , mCurrentFrame(0)
    , mLooping(true)
    , mForwards(true)
{
    //AnimationVertex frame1[] = {
    //	{D3DXVECTOR3(-1.0f, -1.0f, 1.0f), D3DXVECTOR3(0,0,1), D3DXVECTOR2(0,0)},
    //	{D3DXVECTOR3(1.0f, -1.0f, 1.0f), D3DXVECTOR3(0,0,1), D3DXVECTOR2(0,0)},
    //	{D3DXVECTOR3(1.0f, 1.0f, 1.0f), D3DXVECTOR3(0,0,1), D3DXVECTOR2(0,0)},
    //	{D3DXVECTOR3(-1.0f, 1.0f, 1.0f), D3DXVECTOR3(0,0,1), D3DXVECTOR2(0,0)}
    //};
    //AnimationVertex frame2[] = {
    //	{D3DXVECTOR3(-10.0f, -1.0f, 10.0f), D3DXVECTOR3(0,0,1), D3DXVECTOR2(0,0)},
    //	{D3DXVECTOR3(1.0f, -1.0f, 10.0f), D3DXVECTOR3(0,0,1), D3DXVECTOR2(0,0)},
    //	{D3DXVECTOR3(1.0f, 1.0f, 10.0f), D3DXVECTOR3(0,0,1), D3DXVECTOR2(0,0)},
    //	{D3DXVECTOR3(-10.0f, 1.0f, 10.0f), D3DXVECTOR3(0,0,1), D3DXVECTOR2(0,0)}
    //};
    //Framework::VertexBuffer::Description desc;
    //desc.ElementCount = 4;
    //desc.ElementSize = sizeof(AnimationVertex);
    //desc.FirstElementPointer = frame1;
    //desc.Topology = Framework::Topology::TriangleStrip;
    //desc.Usage = Framework::Usage::Default;

    ////desc.
    //Framework::VertexBuffer* buf = new Framework::VertexBuffer(mDevice);
    //buf->SetData(desc, NULL);
    //mKeyFrames.push_back(KeyFrame(buf, 5.0f));
    //desc.FirstElementPointer = frame2;
    //buf = new Framework::VertexBuffer(mDevice);
    //buf->SetData(desc, NULL);
    //mKeyFrames.push_back(KeyFrame(buf, -1.0f));

    assert(keyFrameFilenames.size() == timeSpans.size());
    for (int i = 0; i < keyFrameFilenames.size(); ++i)
    {
        //mKeyFrames.push_back(KeyFrame(Resources::ModelResourceManager::Instance().Load(keyFrameFilenames[i]), timeSpans[i]));
        mKeyFrames.push_back(
            KeyFrame(Resources::D3DResourceManager<Resources::StaticModelData>::Instance().Load(keyFrameFilenames[i])
                     , timeSpans[i]));
    }

    mEffect = Resources::D3DResourceManager<Framework::Effect>::Instance().Load("Animation.fx");
    Framework::InputLayoutVector vec;
    vec.push_back(Framework::InputLayoutElement("POSITION", DXGI_FORMAT_R32G32B32_FLOAT, 0, 0));
    vec.push_back(Framework::InputLayoutElement("NORMAL", DXGI_FORMAT_R32G32B32_FLOAT, 0, 0));
    vec.push_back(Framework::InputLayoutElement("UV", DXGI_FORMAT_R32G32_FLOAT, 0, 0));
    vec.push_back(Framework::InputLayoutElement("POSITION", DXGI_FORMAT_R32G32B32_FLOAT, 1, 1));
    vec.push_back(Framework::InputLayoutElement("NORMAL", DXGI_FORMAT_R32G32B32_FLOAT, 1, 1));
    vec.push_back(Framework::InputLayoutElement("UV", DXGI_FORMAT_R32G32_FLOAT, 1, 1));

    mEffect->GetTechniqueByIndex(0).GetPassByIndex(0).SetInputLayout(vec);
    mEffect->SetVariable("g_t", 0.0f);
    mEffect->SetVariable("g_modelTexture", mKeyFrames[0].Data->MaterialData->GetMaterial(mKeyFrames[0].Data->MaterialName)->MainTexture->GetShaderResourceView());
    mEffect->SetVariable("g_lightDirection", D3DXVECTOR4(50, 50, 0, 0));
}
Пример #3
0
vector<KeyFrame> ModelLoaderMD3::buildKeyFrame(Surface * surfaces,
  const FileName &fileName,
  const FileName &skinName,
  const Header &header,
  TextureFactory &textureFactory) {
	vector<KeyFrame> keyFrames;
	
	const FileName directory = fileName.getPath();
	
	/*
	Only the first frame loads texture files.
	The other frames use a copy of the handles and that copy is stored in here.
	*/
	Material md3Material;
	
	// Take the all the surfaces and push each frame into the mesh manager
	for (int i=0; i<surfaces[0].header.numFrames; ++i) {
		string name = fileName.str() + "#" + itos(i);
		
		// Create a mesh from the surface
		Mesh *mesh = surfaces[0].getObject(i);
		
		// Load a material for the first mesh in the first model.
		// First model only! Ignored for subsequent models
		if (i==0) {
			if (header.numSurfaces > 0) {
				mesh->material.clear();
				
#if 0
				if (surfaces[0].header.numShaders > 0) {
					const char *shaderName=(char*)surfaces[0].shaders[0].name;
					FileName skin = directory.append(FileName(shaderName));
					mesh->material.setTexture(textureFactory.load(skin));
				} else {
					mesh->material.setTexture(textureFactory.load(skinName));
				}
#else
				mesh->material.setTexture(textureFactory.load(skinName));
#endif
				// Keep a copy of the material to propagate to the subsequent frames
				md3Material = mesh->material;
			}
		} else {
			mesh->material = md3Material; // shallow copy
		}
		
		keyFrames.push_back(KeyFrame(mesh));
	}
	
	return keyFrames;
}
Пример #4
0
void KeyFrameAnimation::MakeOrbit(float segments, float timestep, float radius) {
    float start =     -glm::pi<float>() / 2.0f;
    float end   =  2 * glm::pi<float>() - glm::pi<float>() / 2.f;
    float step  = (2 * glm::pi<float>() / segments);
    
    int j = 0;
    for (float f = start; f < end; f += step) {
        float x = radius * glm::cos(f);
        float z = radius * glm::sin(f);
        
        AddKeyFrame(KeyFrame(glm::vec3(x, 25.0f + 2.0f * glm::sin(f), z), j * timestep));        

        j++;
    }

    KeyFrame final = keyFrames[0];
    final.time = keyFrames[KeyFrameCount() - 1].time + timestep;
Пример #5
0
vector<KeyFrame> ModelLoaderMD2::buildKeyFrames(const FileName &fileName,
  const Material &skin,
  const Header &header,
  TexCoord *texCoords,
  Triangle *triangles,
  Frame *frames) {
  
	vector<KeyFrame> keyFrames;
	
	float heightBelowGround=0;
	
	// Take the all the frames and push each frame into the mesh manager
	for (int i=0; i<header.numOfFrames; ++i) {
		string name = fileName.str() + "#" + itos(i);
		
		Mesh *mesh = buildKeyFrame(skin,
		                           header,
		                           texCoords,
		                           triangles,
		                           frames[i]);
		                           
		if (i==0) {
			heightBelowGround = mesh->calculateHeightBelowGround();
		}
		
		// Place the feet of the mesh on the ground
		vec3 *vertices = (vec3*)mesh->vertexArray->lock();
		for (int i=0; i<mesh->vertexArray->getNumber(); ++i) {
			vertices[i].y -= heightBelowGround;
		}
		mesh->vertexArray->unlock();
		
		keyFrames.push_back(KeyFrame(mesh));
	}
	
	return keyFrames;
}
Пример #6
0
 //---------------------------------------------------------------------
 KeyFrame* KeyFrame::_clone(AnimationTrack* newParent) const
 {
     return OGRE_NEW KeyFrame(newParent, mTime);
 }
Пример #7
0
	Animation::State::State( const Animation& animation, json::Value &config )
	{
		length = config["length"].asFloat();
		for(size_t i = 0; i < config["keyframes"].size(); i++)
			keyFrames.push_back(KeyFrame(animation, config["keyframes"][i]));
	}
Пример #8
0
int main(int argc, char *argv[]){
	//Initialise GLFW
	if (!glfwInit()) {
		fprintf(stderr, "There was a problem initializing glfw");
		exit(EXIT_FAILURE);
	}

	//glfw hints
	glfwOpenWindowHint(GLFW_FSAA_SAMPLES, 4);
	glfwOpenWindowHint(GLFW_OPENGL_VERSION_MAJOR, 3);
	glfwOpenWindowHint(GLFW_OPENGL_VERSION_MINOR, 3);
	glfwOpenWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);

	//Open a window
	if (!glfwOpenWindow(WINDOW_WIDTH, WINDOW_HEIGHT, 0, 0, 0, 0, 0, 0, GLFW_WINDOW)) {
		fprintf(stderr, "There was a problem opening a window");
		exit(EXIT_FAILURE);
	}

	//Turn on experimental features to prevent seg fault
	glewExperimental = GL_TRUE;

	//Intitialize GLEW
	if (glewInit() != GLEW_OK) {
		fprintf(stderr, "There was a problem initialising GLEW");
		exit(EXIT_FAILURE);
	}

	//various glfw settings
	glfwEnable(GLFW_STICKY_KEYS);
	glfwSetKeyCallback(&key_callback);
	glfwSetWindowTitle(TITLE);	
	glEnable(GL_CULL_FACE);
	glCullFace(GL_BACK);
	glEnable(GL_DEPTH_TEST);
	glEnable(GL_DEPTH_CLAMP);

	//Create text generator
	GLuint textShaderID = setupShaders("shaders/text/vert.gls", "shaders/text/frag.gls");
	TextGenerator tg((char*)"textures/font.png", textShaderID, ' ', '~', 16, 8, WINDOW_WIDTH, WINDOW_HEIGHT);
	loading(&tg);

	//Load in and set program (Shaders)
	// GLuint simpleShaderID = setupShaders("shaders/simple/vert.gls", "shaders/simple/frag.gls");
	// GLuint phongShaderID = setupShaders("shaders/phong/vert.gls", "shaders/phong/frag.gls");
	GLuint perFragmentShaderID = setupShaders("shaders/perFragment/vert.gls", "shaders/perFragment/frag.gls");

	//Load in terrain and sky box
	HeightMapLoader groundObj = HeightMapLoader("textures", "img2.png");
	ObjLoader skyboxObj = ObjLoader("models","skybox.obj");

	Object ground(&groundObj, perFragmentShaderID, viewer, GL_FILL);
	Skybox skybox(&skyboxObj, perFragmentShaderID, viewer, GL_FILL);
	loading(&tg);

	//Load in thunder birds
	ObjLoader thunderBird1Obj = ObjLoader("models", "thunderbird1.obj");
	ObjLoader t2ContainerObj = ObjLoader("models","t2container.obj");
	ObjLoader thunderBird2Obj = ObjLoader("models","thunderbird2.obj");
	ObjLoader thunderBird3Obj = ObjLoader("models","thunderbird3.obj");
	ObjLoader eggObj = ObjLoader("models", "egg.obj");

	Object thunderBird1(&thunderBird1Obj, perFragmentShaderID, viewer, GL_FILL);
	Object thunderBird1B(&thunderBird1Obj, perFragmentShaderID, viewer, GL_FILL);
	Object thunderBird1C(&thunderBird1Obj, perFragmentShaderID, viewer, GL_FILL);

	Object t2container(&t2ContainerObj, perFragmentShaderID, viewer, GL_FILL);
	Object thunderBird2(&thunderBird2Obj, perFragmentShaderID, viewer, GL_FILL);
	Object t2containerB(&t2ContainerObj, perFragmentShaderID, viewer, GL_FILL);
	Object thunderBird2B(&thunderBird2Obj, perFragmentShaderID, viewer, GL_FILL);

	Object thunderBird3(&thunderBird3Obj, perFragmentShaderID, viewer, GL_FILL);
	Object thunderBird3B(&thunderBird3Obj, perFragmentShaderID, viewer, GL_FILL);
	Object thunderBird3C(&thunderBird3Obj, perFragmentShaderID, viewer, GL_FILL);
	loading(&tg);

	//Set up collisions
	viewer->addTerrain(&ground);

	loading(&tg);

	thunderBird1.setPosition(glm::vec3(-2,0.1,0));

	t2container.setPosition(glm::vec3(-7.5,0.15,5));
	t2container.setScale(glm::vec3(0.2,0.2,0.2));
	t2container.setRotation(90, glm::vec3(0,1,0));

	thunderBird2.setPosition(glm::vec3(-7.5,0.15,5));
	thunderBird2.setScale(glm::vec3(0.2,0.2,0.2));
	thunderBird2.setRotation(90, glm::vec3(0,1,0));

	t2containerB.setPosition(glm::vec3(-13.7941, 0.0, -11.716));
	t2containerB.setScale(glm::vec3(0.2,0.2,0.2));
	t2containerB.setRotation(120, glm::vec3(0,1,0));

	thunderBird2B.setPosition(glm::vec3(-13.7941, 0.0, -11.716));
	thunderBird2B.setScale(glm::vec3(0.2,0.2,0.2));
	thunderBird2B.setRotation(120, glm::vec3(0,1,0));


	thunderBird3.setPosition(glm::vec3(2,2,12.5));
	thunderBird3.setScale(glm::vec3(0.4,0.4,0.4));
	thunderBird3.setRotation(-90, glm::vec3(1,0,0));

	thunderBird3B.setPosition(glm::vec3(22.3989, 0.541667, -5.00961));
	thunderBird3B.setScale(glm::vec3(0.4,0.4,0.4));
	thunderBird3B.setRotation(-90, glm::vec3(1,0,0));

	thunderBird3B.setPosition(glm::vec3(2,2,12.5));
	thunderBird3B.setScale(glm::vec3(0.4,0.4,0.4));
	thunderBird3B.setRotation(-90, glm::vec3(1,0,0));


	ground.setScale(glm::vec3(0.35,0.025,0.35));
	ground.setPosition(glm::vec3(-groundObj.width/2 * 0.35,0,-groundObj.height/2 * 0.35));

	std::vector<glm::vec3> positions;

	positions.push_back(glm::vec3(-6.42059,0.25837,4.494014));
	positions.push_back(glm::vec3(-3.85007,0.1,7.12377));
	positions.push_back(glm::vec3(-0.601204,0.1,3.592329));
	positions.push_back(glm::vec3(8.2538,0.1,2.5428));
	positions.push_back(glm::vec3(10.6809,0.38337,-3.84069));
	positions.push_back(glm::vec3(-5.13897,0.1,-11.4451));
	positions.push_back(glm::vec3(-14.3374,0.1,-8.11471));
	positions.push_back(glm::vec3(-20.2777, 0.1, 8.26625));
	positions.push_back(glm::vec3(-22.3929, 1.35833,19.6362));
	positions.push_back(glm::vec3(1.64004, 0.1, 33.6688));
	positions.push_back(glm::vec3(30.9513, 0.683333, 18.214));
	positions.push_back(glm::vec3(32.9145, 1.56667, -11.0445));
	positions.push_back(glm::vec3(31.17666, 0.808333, -22.8479));
	positions.push_back(glm::vec3(-29.7966, 0.35, -27.9126));
	positions.push_back(glm::vec3(-33.6018, 0.433333, -25.1177));
	positions.push_back(glm::vec3(-29.1175, 2.39167, -17.2737));
	positions.push_back(glm::vec3(-27.6434, 2.1833, -14.5711));
	positions.push_back(glm::vec3(-33.0654, 3.5, 2.62864));
	positions.push_back(glm::vec3(-20.6909, 4, 3.49496));
	positions.push_back(glm::vec3(-3.85007, 3.5 , 7.12377));
	positions.push_back(glm::vec3(1.42417, 2.116667, 0.276567));



	WayPoint w1 = WayPoint(positions[0], positions[1] - positions[0]);
	WayPoint w2 = WayPoint(positions[1], positions[2] - positions[1]);
	WayPoint w3 = WayPoint(positions[2], positions[3] - positions[2]);
	WayPoint w4 = WayPoint(positions[3], positions[4] - positions[3]);
	WayPoint w5 = WayPoint(positions[4], positions[5] - positions[4]);
	WayPoint w6 = WayPoint(positions[5], positions[6] - positions[5]);
	WayPoint w7 = WayPoint(positions[6], positions[7] - positions[6]);
	WayPoint w8 = WayPoint(positions[7], positions[8] - positions[7]);
	WayPoint w9 = WayPoint(positions[8], positions[9] - positions[8]);
	WayPoint w10 = WayPoint(positions[9], positions[10] - positions[9]);
	WayPoint w11 = WayPoint(positions[10], positions[11] - positions[10]);
	WayPoint w12 = WayPoint(positions[11], positions[12] - positions[11]);
	WayPoint w13 = WayPoint(positions[12], positions[13] - positions[12]);
	WayPoint w14 = WayPoint(positions[13], positions[14] - positions[13]);
	WayPoint w15 = WayPoint(positions[14], positions[15] - positions[14]);
	WayPoint w16 = WayPoint(positions[15], positions[16] - positions[15]);
	WayPoint w17 = WayPoint(positions[16], positions[17] - positions[16]);
	WayPoint w18 = WayPoint(positions[17], positions[18] - positions[17]);
	WayPoint w19 = WayPoint(positions[18], positions[19] - positions[18]);
	WayPoint w20 = WayPoint(positions[19], positions[20] - positions[19]);
	WayPoint w21 = WayPoint(positions[20], glm::vec3(0,0,1));

	t.addWayPoint(0.0, &w1, 1);
	t.addWayPoint(2.0, &w2, 1);
	t.addWayPoint(4.0, &w3, 1);
	t.addWayPoint(6.0, &w4, 1);
	t.addWayPoint(8.0, &w5, 1);
	t.addWayPoint(10.0, &w6, 1);
	t.addWayPoint(12.0, &w7, 1);
	t.addWayPoint(14.0, &w8, 1);
	t.addWayPoint(16.0, &w9, 1);
	t.addWayPoint(18.0, &w10, 1);
	t.addWayPoint(20.0, &w11, 1);
	t.addWayPoint(22.0, &w12, 1);
	t.addWayPoint(24.0, &w13, 1);
	t.addWayPoint(26.0, &w14, 1);
	t.addWayPoint(28.0, &w15, 1);
	t.addWayPoint(30.0, &w16, 1);
	t.addWayPoint(32.0, &w17, 1);
	t.addWayPoint(34.0, &w18, 1);
	t.addWayPoint(36.0, &w19, 1);
	t.addWayPoint(38.0, &w20, 1);
	t.addWayPoint(40.0, &w21, 1);

	Animutator* tb1Anim = new Animutator();

	KeyFrame tb1KF1 = KeyFrame(glm::vec3(0,1,1), 90, glm::vec3(0,1,0), glm::vec3(0.5,0.5,0.5));
	KeyFrame tb1KF2 = KeyFrame(glm::vec3(10,1,1), 90, glm::vec3(0,1,0), glm::vec3(0.5,0.5,0.5));
	KeyFrame tb1KF3 = KeyFrame(glm::vec3(10,1,1), -90, glm::vec3(0,1,0), glm::vec3(0.5,0.5,0.5)); 
	KeyFrame tb1KF4 = KeyFrame(glm::vec3(0,1,1), -90, glm::vec3(0,1,0), glm::vec3(0.5,0.5,0.5));

	tb1Anim->addKeyFrame(0.0, &tb1KF1);
	tb1Anim->addKeyFrame(10.0, &tb1KF2);
	tb1Anim->addKeyFrame(12.5, &tb1KF3);
	tb1Anim->addKeyFrame(22.5, &tb1KF4);
	tb1Anim->addKeyFrame(25.0, &tb1KF1);

	thunderBird1.addAnimutator(tb1Anim);


	Animutator* tb1BAnim = new Animutator();

	KeyFrame tb1BKF1 = KeyFrame(glm::vec3(-23.027, 1.35, 16.35409), -110.328, glm::vec3(0,1,0), glm::vec3(0.5,0.5,0.5));
	KeyFrame tb1BKF2 = KeyFrame(glm::vec3(-24.5907, 2.29167, 15.7748), -110.328, glm::vec3(0,1,0), glm::vec3(0.5,0.5,0.5));
	KeyFrame tb1BKF3 = KeyFrame(glm::vec3(-24.5907, 2.29167, 15.7748), -38.604, glm::vec3(0,1,0), glm::vec3(0.5,0.5,0.5));
	KeyFrame tb1BKF4 = KeyFrame(glm::vec3(-32.497, 1, 25.6773), -38.604, glm::vec3(0,1,0), glm::vec3(0.5,0.5,0.5)); 
	KeyFrame tb1BKF5 = KeyFrame(glm::vec3(-32.497, 1, 25.6773), 5.98309, glm::vec3(0,1,0), glm::vec3(0.5,0.5,0.5)); 
	KeyFrame tb1BKF6 = KeyFrame(glm::vec3(-31.8602, 1.55833, 31.7533), 5.98309, glm::vec3(0,1,0), glm::vec3(0.5,0.5,0.5));
	KeyFrame tb1BKF7 = KeyFrame(glm::vec3(-31.8602, 1.55833, 31.7533), 38.384, glm::vec3(0,1,0), glm::vec3(0.5,0.5,0.5));
	KeyFrame tb1BKF8 = KeyFrame(glm::vec3(-28.5349, 1, 35.9512), 38.384, glm::vec3(0,1,0), glm::vec3(0.5,0.5,0.5));
	KeyFrame tb1BKF9 = KeyFrame(glm::vec3(-28.5349, 1, 35.9512), 99.0798, glm::vec3(0,1,0), glm::vec3(0.5,0.5,0.5));
	KeyFrame tb1BKF10 = KeyFrame(glm::vec3(-13.2714, 1, 33.5119), 99.0798, glm::vec3(0,1,0), glm::vec3(0.5,0.5,0.5));
	KeyFrame tb1BKF11 = KeyFrame(glm::vec3(-13.2714, 1, 33.5119), -150.378, glm::vec3(0,1,0), glm::vec3(0.5,0.5,0.5));
	KeyFrame tb1BKF12 = KeyFrame(glm::vec3(-23.027, 1.35, 16.35409), -150.378, glm::vec3(0,1,0), glm::vec3(0.5,0.5,0.5));

	tb1BAnim->addKeyFrame(0.0, &tb1BKF1);
	tb1BAnim->addKeyFrame(5.0, &tb1BKF2);
	tb1BAnim->addKeyFrame(5.5, &tb1BKF3);
	tb1BAnim->addKeyFrame(10.5, &tb1BKF4);
	tb1BAnim->addKeyFrame(11.0, &tb1BKF5);
	tb1BAnim->addKeyFrame(16.0, &tb1BKF6);
	tb1BAnim->addKeyFrame(16.5, &tb1BKF7);
	tb1BAnim->addKeyFrame(21.5, &tb1BKF8);
	tb1BAnim->addKeyFrame(22.0, &tb1BKF9);
	tb1BAnim->addKeyFrame(27.0, &tb1BKF10);
	tb1BAnim->addKeyFrame(27.5, &tb1BKF11);
	tb1BAnim->addKeyFrame(32.5, &tb1BKF12);
	tb1BAnim->addKeyFrame(33.0, &tb1BKF1);

	thunderBird1B.addAnimutator(tb1BAnim);

	Animutator* tb1CAnim = new Animutator();

	KeyFrame tb1CKF1 = KeyFrame(glm::vec3(25.7527, 1.5, -29.4807), -77.7031, glm::vec3(0,1,0), glm::vec3(0.5,0.5,0.5));
	KeyFrame tb1CKF2 = KeyFrame(glm::vec3(-24.549, 2.76667, -18.516), -77.7031, glm::vec3(0,1,0), glm::vec3(0.5,0.5,0.5));
	KeyFrame tb1CKF3 = KeyFrame(glm::vec3(-24.549, 2.76667, -18.516), 102.297, glm::vec3(0,1,0), glm::vec3(0.5,0.5,0.5)); 
	KeyFrame tb1CKF4 = KeyFrame(glm::vec3(25.7527, 1.5, -29.4807), 102.297, glm::vec3(0,1,0), glm::vec3(0.5,0.5,0.5));

	tb1CAnim->addKeyFrame(0.0, &tb1CKF1);
	tb1CAnim->addKeyFrame(7.5, &tb1CKF2);
	tb1CAnim->addKeyFrame(9, &tb1CKF3);
	tb1CAnim->addKeyFrame(16.5, &tb1CKF4);
	tb1CAnim->addKeyFrame(18, &tb1CKF1);

	thunderBird1C.addAnimutator(tb1CAnim);


	Animutator* tb2cAnim = new Animutator();

	KeyFrame tbc2KF1 = KeyFrame(glm::vec3(-7.5, 0.15, 5), 90, glm::vec3(0,1,0), glm::vec3(0.2,0.2,0.2));
	KeyFrame tbc2KF2 = KeyFrame(glm::vec3(-7.5, -0.3, 5), 90, glm::vec3(0,1,0), glm::vec3(0.2,0.2,0.2));

	tb2cAnim->addKeyFrame(0.0, &tbc2KF1);
	tb2cAnim->addKeyFrame(5.0, &tbc2KF2);
	tb2cAnim->addKeyFrame(5.5, &tbc2KF2);
	tb2cAnim->addKeyFrame(10.0, &tbc2KF1);
	tb2cAnim->addKeyFrame(10.5, &tbc2KF1);

	t2container.addAnimutator(tb2cAnim);

	Animutator* tb2cBAnim = new Animutator();

	KeyFrame tbc2BKF1 = KeyFrame(glm::vec3(-13.7941, 0.0, -11.716), 120, glm::vec3(0,1,0), glm::vec3(0.2,0.2,0.2));
	KeyFrame tbc2BKF2 = KeyFrame(glm::vec3(-13.7941, -0.4, -11.716), 120, glm::vec3(0,1,0), glm::vec3(0.2,0.2,0.2));

	tb2cBAnim->addKeyFrame(0.0, &tbc2BKF1);
	tb2cBAnim->addKeyFrame(5.0, &tbc2BKF2);
	tb2cBAnim->addKeyFrame(5.5, &tbc2BKF2);
	tb2cBAnim->addKeyFrame(10.0, &tbc2BKF1);
	tb2cBAnim->addKeyFrame(10.5, &tbc2BKF1);

	t2containerB.addAnimutator(tb2cBAnim);


	Animutator* tb3cAnim = new Animutator();
	KeyFrame tb3KF1 = KeyFrame(glm::vec3(2, 1.90, 12.5), -90, glm::vec3(1,0,0), glm::vec3(0.4,0.4,0.4));
	KeyFrame tb3KF2 = KeyFrame(glm::vec3(2, 4, 12.5), -90, glm::vec3(1,0,0), glm::vec3(0.4,0.4,0.4));

	tb3cAnim->addKeyFrame(0.0, &tb3KF1);
	tb3cAnim->addKeyFrame(5.0, &tb3KF2);
	tb3cAnim->addKeyFrame(10.0, &tb3KF1);

	thunderBird3.addAnimutator(tb3cAnim);

	Animutator* tb3BcAnim = new Animutator();
	KeyFrame tb3BKF1 = KeyFrame(glm::vec3(22.3989, 2, -5.00961), -90, glm::vec3(1,0,0), glm::vec3(0.4,0.4,0.4));
	KeyFrame tb3BKF2 = KeyFrame(glm::vec3(22.3989, 4.5, -5.00961), -90, glm::vec3(1,0,0), glm::vec3(0.4,0.4,0.4));

	tb3BcAnim->addKeyFrame(0.0, &tb3BKF1);
	tb3BcAnim->addKeyFrame(5.0, &tb3BKF2);
	tb3BcAnim->addKeyFrame(10.0, &tb3BKF1);

	thunderBird3B.addAnimutator(tb3BcAnim);

	Animutator* tb3CcAnim = new Animutator();
	KeyFrame tb3CKF1 = KeyFrame(glm::vec3(-30.3314, 1.9, 2.7756), -90, glm::vec3(1,0,0), glm::vec3(0.4,0.4,0.4));
	KeyFrame tb3CKF2 = KeyFrame(glm::vec3(-30.3314, 4.6, 2.7756), -90, glm::vec3(1,0,0), glm::vec3(0.4,0.4,0.4));

	tb3CcAnim->addKeyFrame(0.0, &tb3CKF1);
	tb3CcAnim->addKeyFrame(5.0, &tb3CKF2);
	tb3CcAnim->addKeyFrame(10.0, &tb3CKF1);

	thunderBird3C.addAnimutator(tb3CcAnim);

	int frame_count = 0;
	int last_fps = 0; 
	GLfloat lastTime = glfwGetTime();

	loading(&tg);

	do {
		glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);

		if(tour){
			t.update();
		} else {
			viewer->update();
		}

		thunderBird1.draw();
		thunderBird1B.draw();
		thunderBird1C.draw();

		thunderBird2.draw();
		t2container.draw();
		thunderBird2B.draw();
		t2containerB.draw();

		thunderBird3.draw();
		thunderBird3B.draw();
		thunderBird3C.draw();

		ground.draw();
		skybox.draw();

		if(glfwGetTime() - lastTime < 1) {
			frame_count++;
		} else {
			lastTime = glfwGetTime();
			last_fps = frame_count;
			frame_count = 0;
		}

		if(show_help){
			showHelp(tg, last_fps);
		}

		glfwSwapBuffers();
	} while ( (glfwGetKey(GLFW_KEY_ESC) != GLFW_PRESS) && 
			(glfwGetKey('q') != GLFW_PRESS) &&
			(glfwGetKey('Q') != GLFW_PRESS) &&
			(glfwGetWindowParam( GLFW_OPENED )) );

	glfwTerminate();

	//Everything was okay, return success
	exit(EXIT_SUCCESS);
}
Пример #9
0
void BoneModel::CreateAnime(vmd& VMD){

	auto& bones = mBoneAssetDataPtr->GetFileData().GetBoneData().mBoneBuffer;
	if (bones.size() == 0)return;
	mIsCreateAnime = true;

	mMotion.clear();

	DWORD mBoneNum = mBone.size();
	mMotion.resize(mBoneNum);

	mLastKeyNo = 0;

	for (unsigned int i = 0; i < VMD.mKeyNum; i++){
		auto& key = VMD.mKeyFrame[i];

		DWORD bid = 0;
		for (; bid < mBoneNum; bid++){
			if (mBone[bid].mStrName == key.BoneName){
				break;
			}
		}
		if (bid >= mBoneNum){
			continue;
		}

		Motion& mot = mMotion[bid];
		KeyFrame temp = KeyFrame(key);

		//相対値から絶対値に変更
		temp.mKeyFrame.Location[0] += mBone[bid].mPos.x;
		temp.mKeyFrame.Location[1] += mBone[bid].mPos.y;
		temp.mKeyFrame.Location[2] += mBone[bid].mPos.z;

		mot.mKeyFrame.push_back(temp);



		if (temp.mKeyFrame.FrameNo > mLastKeyNo){
			mLastKeyNo = temp.mKeyFrame.FrameNo;
		}

	}
	for (DWORD mid = 0; mid < mBoneNum; mid++){
		std::sort(mMotion[mid].mKeyFrame.begin(), mMotion[mid].mKeyFrame.end());

		if (mMotion[mid].mKeyFrame.size() == 0){
			Motion& mot = mMotion[mid];
			vmd::VMDKeyFrame key;
			const char* c = mBone[mid].mStrName.c_str();
			for (int i = 0; i < 15; i++){
				key.BoneName[i] = c[i];
				if (c[i] == '\0')break;
			}
			key.FrameNo = 0;
			key.Rotatation[0] = 0.0f;
			key.Rotatation[1] = 0.0f;
			key.Rotatation[2] = 0.0f;
			key.Rotatation[3] = 0.0f;
			for (int i = 0; i < 64; i++)
				key.Interpolation[i] = (char)0.0f;


			//相対値から絶対値に変更
			key.Location[0] = mBone[mid].mPos.x;
			key.Location[1] = mBone[mid].mPos.y;
			key.Location[2] = mBone[mid].mPos.z;

			KeyFrame temp = KeyFrame(key);
			mot.mKeyFrame.push_back(temp);

		}
	}
}
Пример #10
0
  void
  SVGAnimateMotionElement::animationTraverse(svgl::AnimationInfo* animinfo)
  {
    _elementToAnimate = animinfo->element;
    _translateToAnimate = 0;

    SVGTransformable* toAnimate = dynamic_cast<SVGTransformable*>(_elementToAnimate);
    if(!toAnimate) {
      std::cerr << "element refered by 'animateMotion' is not a SVGTransformable" << __FL__;
      return;
    }
    Attribute< SVGAnimatedTransformList >& transform = toAnimate->transform;
    {
      std::vector <float> v;
      v.push_back(0);
      v.push_back(0);
      _translateToAnimate = new SVGTranslateTransform(v);
    }
    MYGET_ANIMATED_VAL(transform).insertItemBefore(_translateToAnimate, 0);

    _doBezierAnim=false;
    _doRotateAnim = rotate_no;
    _rotateToAnimate=0;

    const SVGNumberList& keytimes = GET_SIMPLE_VAL(KeyTimes);
    const SVGPathSegList* pl=0;

    dom::Node *n = getFirstChild();
    if(n) {
      SVGMPathElement* mpath = 0;
      for(;n;n=n->getNextSibling()) {
	mpath = dynamic_cast<SVGMPathElement*>(n);
	if(mpath)
	  break;
      }
      if(mpath) {
	unicode::String* href = mpath->GET_SIMPLE_VAL(Href);
	if(href->getLength()) {
	  dom::Element* de = animinfo->externalEntityManager->get(href, getOwnerDocument());
	  //dom::Element* de = GET_SIMPLE_VAL(OwnerSVGElement)->getElementById(href->substring(1));
	  SVGPathElement* path = dynamic_cast<SVGPathElement*>(de);
	  if(de)
	    pl = &(path->GET_SIMPLE_VAL(PathSegList));
	}
      }
    }
    else
      pl = &(GET_SIMPLE_VAL(Path));

    if (pl && pl->numberOfItems()>=2) {
      BezierPath bezier;
      for(unsigned int i=0; i<pl->numberOfItems(); ++i) {
	const SVGPathSeg* p = pl->getItem(i);
	p->updateBezier(bezier);
      }
      _distanceIter = new svgl::BezierPathDistanceIterator(bezier,.1);
      _bezierLength = svgl::length(bezier);

      unicode::String* rotate_ptr = GET_SIMPLE_VAL(Rotate);
      unicode::String& rotate = *rotate_ptr;

      if (rotate_ptr && rotate.getLength()) {
	static unicode::String
	  &auto_string = *unicode::String::internString("auto"),
	  &auto_reverse_string = *unicode::String::internString("auto-reverse");
	float rot=0;
	if(rotate==auto_string) {
	  _doRotateAnim=rotate_auto;
	}
	else if(rotate==auto_reverse_string) {
	  _doRotateAnim=rotate_auto_reverse;
	}
	else {
	  if (unicode::get_float(rotate, &rot)) {
	    _doRotateAnim=rotate_angle;
	  }
	}
	if(_doRotateAnim!=rotate_no) {
	  std::vector<float> v;
	  v.push_back(rot);
	  v.push_back(0);
	  v.push_back(0);
	  _rotateToAnimate = new SVGRotateTransform(v);
	  MYGET_ANIMATED_VAL(transform).insertItemBefore(_rotateToAnimate, 1);
	}
      }
      _doBezierAnim = true;
    }

    else {
      const SVGLengthList& values = GET_SIMPLE_VAL(Values);
      unsigned int valuesSize = values.numberOfItems();
      if(valuesSize) {
	if(valuesSize % 2) {
	  std::cerr << "'values' for 'animateMotion' must be a list of pair of length" << __FL__;
	  return;
	}
	if(keytimes.numberOfItems()) {
	  if(keytimes.numberOfItems()!=values.numberOfItems()) {
	    std::cerr << "'keyTimes' and 'values' have different size" << __FL__;
	    return;
	  }
	  for(unsigned int i=0;
	      i<values.numberOfItems();
	      ++++i) {
	    SVGLength l = values.getItem(i);
	    float v1 = l.computeValue();
	    l = values.getItem(i+1);
	    float v2 = l.computeValue();
	    //_keyFrames.push_back(KeyFrame(KeyFrame::ValueType<float,float>(v1,v2), keytimes.getItem(i).getValue().getValue()));
	    _keyFrames.push_back(KeyFrame(KeyFrame::ValueType(v1,v2), keytimes.getItem(i).GET_SIMPLE_VAL(Value)));
	  }
	}
	else {
	  unsigned int num = values.numberOfItems();
	  float t=0;
	  float dt=1./((num>>1)-1);
	  for(unsigned int i=0;
	      i<num;
	      ++++i) {
	    SVGLength l = values.getItem(i);
	    float v1 = l.computeValue();
	    l = values.getItem(i+1);
	    float v2 = l.computeValue();
	    _keyFrames.push_back(KeyFrame(KeyFrame::ValueType(v1,v2), t));
	    t+=dt;
	  }
	}
      
      }
      else {
	unicode::String* fromstr = GET_SIMPLE_VAL(From);
	unicode::String* tostr = GET_SIMPLE_VAL(To);
	unicode::String* bystr = GET_SIMPLE_VAL(By);
	//std::cerr << DBGVAR(attrName) << DBGVAR(attrType) << DBGVAR(fromstr) << DBGVAR(tostr) << __FL__;

	SVGList<SVGLength> from, to, by;
	bool fromb=false, tob=false, byb=false;

	svgl::read(fromstr,from);
	svgl::read(tostr,to);
	svgl::read(bystr,by);

	fromb = (from.numberOfItems()>0);
	tob = (to.numberOfItems()>0);
	byb = (by.numberOfItems()>0);

	// std::cerr << DBGVAR(fromb) << DBGVAR(tob) << DBGVAR(byb) << __FL__;

	if( !(fromb||tob||byb) ) {
	  std::cerr << "'from', 'to' and 'by' are unset" << __FL__;
	  return;
	}

	if(fromb && from.numberOfItems()!=2) {
	  std::cerr << "'from' for 'animateMotion' must be a pair of length" << __FL__;
	  return;
	}

	if(tob && to.numberOfItems()!=2) {
	  std::cerr << "'to' for 'animateMotion' must be a pair of length" << __FL__;
	  return;
	}

	if(byb && by.numberOfItems()!=2) {
	  std::cerr << "'by' for 'animateMotion' must be a pair of length" << __FL__;
	  return;
	}

	// FIXME
	// from is not computed with right dpi...
	if(!fromb) {
	  static unicode::String
	    *x_string = unicode::String::internString("x"),
	    *y_string = unicode::String::internString("y");
	  svgl::AnimateAdapter* x = _elementToAnimate->getAttributeByName(x_string);
	  if(x==0 || !x->canBeSetAsDouble()) {
	    std::cerr << "attribute 'x' of the element referenced by 'animateMotion' can not be set as double" << __FL__;
	    return;
	  }

	  svgl::AnimateAdapter* y = _elementToAnimate->getAttributeByName(y_string);
	  if(y==0 || !y->canBeSetAsDouble()) {
	    std::cerr << "attribute 'y' of the element referenced by 'animateMotion' can not be set as double" << __FL__;
	    return;
	  }

	  SVGLength l;
	  l.newValueSpecifiedUnits(SVGLength::SVG_LENGTHTYPE_NUMBER, x->getBaseVal());
	  from.replaceItem(l,0);
	  l.newValueSpecifiedUnits(SVGLength::SVG_LENGTHTYPE_NUMBER, y->getBaseVal());
	  from.replaceItem(l,1);

	  fromb=true;
	}
	if(!tob) {
	  if(byb) {	  
	    to.replaceItem(from.getItem(0)+by.getItem(0), 0);
	    to.replaceItem(from.getItem(1)+by.getItem(1), 1);
	  }
#if 0
	  else {
	    STDDBG;
	    return;
	  }
#endif
	}

	if(fromb)
	  _keyFrames.push_back(KeyFrame( KeyFrame::ValueType(from.getItem(0).GET_SIMPLE_VAL(Value), from.getItem(1).GET_SIMPLE_VAL(Value)), 0));
	_keyFrames.push_back(KeyFrame( KeyFrame::ValueType(to.getItem(0).GET_SIMPLE_VAL(Value), to.getItem(1).GET_SIMPLE_VAL(Value)), 1));
      }

#if 0
      STDDBG;
      for(unsigned int j=0; j<_keyFrames.size(); ++j) {
	std::cerr << "( <" << _keyFrames[j].value.first << "," << _keyFrames[j].value.second << ">, " << _keyFrames[j].time << ")";
      }
      std::cerr << std::endl;
#endif
    }
void copyAiAnimation(const aiScene *scene, const aiMesh *sourceMesh, const unsigned int &animationIndex,
    std::map<std::string, unsigned int> &boneNameToIndex,
    std::map<std::string, const aiNode *> &nodeNameToPointer,
    std::map<std::string, aiMatrix4x4> &nodeNameToMatrix,
    Skeleton &skeleton)
{
    const aiAnimation *sourceAnimation = scene->mAnimations[animationIndex];
    const std::string animationName = std::string(sourceAnimation->mName.data);
    skeleton.animations.insert(std::pair<std::string, Animation>(animationName, Animation()));
    Animation *animation = &skeleton.animations[animationName];
    const size_t nrFrames = getAiNrAnimationFrames(sourceAnimation);
    
    animation->name = animationName;
    animation->frames.assign(nrFrames*skeleton.bones.size(), KeyFrame());
    
    if (sourceAnimation->mNumChannels != skeleton.bones.size())
    {
        std::cerr << "Warning: animation '" << animation->name << "' has an invalid number of channels (" << sourceAnimation->mNumChannels << " for " << skeleton.bones.size() << " bones)!" << std::endl;
    }
    
    //Store inverse of global transformation.
    aiMatrix4x4 inverseGlobalTransformation = scene->mRootNode->mTransformation;
    
    inverseGlobalTransformation.Inverse();
    
    //Process all frames.
    KeyFrame *frames = &animation->frames[0];
    
    for (size_t frame = 0; frame < nrFrames; ++frame)
    {
        //For this frame, first reset all transformations to their originals.
        for (std::map<std::string, aiMatrix4x4>::iterator i = nodeNameToMatrix.begin(); i != nodeNameToMatrix.end(); ++i)
        {
            assert(nodeNameToPointer[i->first]);
            i->second = nodeNameToPointer[i->first]->mTransformation;
        }
        
        //Then, retrieve all transformations that are stored in the animation data for the corresponding nodes.
        for (size_t i = 0; i < sourceAnimation->mNumChannels; ++i)
        {
            const aiNodeAnim *nodeAnim = sourceAnimation->mChannels[i];
            
            //Get data for this frame.
            aiVector3D scale(1.0f, 1.0f, 1.0f);
            aiQuaternion rotate(1.0f, 0.0f, 0.0f, 0.0f);
            aiVector3D translate(0.0f, 0.0f, 0.0f);
            
            if (frame < nodeAnim->mNumScalingKeys) scale = nodeAnim->mScalingKeys[frame].mValue;
            else if (nodeAnim->mNumScalingKeys > 0) scale = nodeAnim->mScalingKeys[nodeAnim->mNumScalingKeys - 1].mValue;
            if (frame < nodeAnim->mNumRotationKeys) rotate = nodeAnim->mRotationKeys[frame].mValue;
            else if (nodeAnim->mNumRotationKeys > 0) rotate = nodeAnim->mRotationKeys[nodeAnim->mNumRotationKeys - 1].mValue;
            if (frame < nodeAnim->mNumPositionKeys) translate = nodeAnim->mPositionKeys[frame].mValue;
            else if (nodeAnim->mNumPositionKeys > 0) translate = nodeAnim->mPositionKeys[nodeAnim->mNumPositionKeys - 1].mValue;
            
            //Create transformation matrix.
            if (nodeNameToMatrix.find(nodeAnim->mNodeName.data) == nodeNameToMatrix.end())
            {
                std::cerr << "Warning: animation data for node '" << nodeAnim->mNodeName.data << "' is not available!" << std::endl;
                throw std::exception();
            }
            
            aiMatrix4x4 scaleMatrix;
            aiMatrix4x4 rotationMatrix = aiMatrix4x4(rotate.GetMatrix());
            aiMatrix4x4 translationMatrix;
            
            aiMatrix4x4::Scaling(scale, scaleMatrix);
            aiMatrix4x4::Translation(translate, translationMatrix);
            
            nodeNameToMatrix[nodeAnim->mNodeName.data] = translationMatrix*rotationMatrix*scaleMatrix;
        }
        
        //Recursively update these transformations.
        updateAiNodeMatrices(scene->mRootNode, aiMatrix4x4(), nodeNameToMatrix);

        //Assign the updated transformations to the corresponding bones.
        for (std::map<std::string, aiMatrix4x4>::const_iterator i = nodeNameToMatrix.begin(); i != nodeNameToMatrix.end(); ++i)
        {
            std::map<std::string, unsigned int>::const_iterator boneIterator = boneNameToIndex.find(i->first);
            
            if (boneIterator != boneNameToIndex.end())
            {
                const unsigned int boneIndex = boneIterator->second;
                //const aiMatrix4x4 finalTransformation = inverseGlobalTransformation*i->second*sourceMesh->mBones[boneIndex]->mOffsetMatrix;
                const aiMatrix4x4 finalTransformation = i->second*sourceMesh->mBones[boneIndex]->mOffsetMatrix;
                
                aiVector3D scale(1.0f, 1.0f, 1.0f);
                aiQuaternion rotate(1.0f, 0.0f, 0.0f, 0.0f);
                aiVector3D translate(0.0f, 0.0f, 0.0f);
                
                finalTransformation.Decompose(scale, rotate, translate);
                
                frames[boneIndex] = KeyFrame(vec3(scale.x, scale.y, scale.z),
                                             frame,
                                             quatconj(vec4(rotate.x, rotate.y, rotate.z, rotate.w)),
                                             vec4(translate.x, translate.y, translate.z, 0.0f));
            }
        }
        
        //Advance to next frame.
        frames += skeleton.bones.size();
    }
    
#ifndef NDEBUG
    std::cerr << "Added animation '" << animation->name << "' with " << nrFrames << " frames, resulting in " << animation->frames.size() << " keyframes." << std::endl;
#endif
}
Пример #12
0
	void PuppetEditor::Update()
	{
		Editor::Update();

		if (isEnabled)
		{
			UpdateCamera();

			timeline->currentAnimation = puppetEntity->puppet.GetCurrentAnimation();

			Animation *anim = puppetEntity->puppet.GetCurrentAnimation();

			if (Input::IsKeyPressed(keyTogglePause))
			{
				puppetEntity->puppet.TogglePause();
				Debug::render = Debug::showBounds = puppetEntity->puppet.IsPaused();
				if (!puppetEntity->puppet.IsPaused())
				{
					Debug::selectedEntity = NULL;
				}
				else
				{
					if (anim)
					{
						anim->SetCurrentTime(int(anim->GetCurrentTime()/TIME_STEP)*TIME_STEP);
					}
				}
			}

			if (puppetEntity->puppet.IsPaused())
			{
				if (Input::IsMouseButtonPressed(MOUSE_BUTTON_LEFT))
					Debug::selectedEntity = scene->GetNearestEntityByControlPoint(Input::GetWorldMousePosition(), "", Debug::selectedEntity);

				if (Input::IsKeyHeld(KEY_LCTRL))
				{
					if (Input::IsKeyPressed(KEY_S))
					{
						puppetEntity->puppet.Save();
					}
				}

				if (Debug::selectedEntity)
				{
					Part *part = dynamic_cast<Part*>(Debug::selectedEntity);

					float moveSpeed = 10.0f;
					float rotateSpeed = 15.0f;

					if (Input::IsKeyHeld(KEY_LSHIFT))
					{
						float multiplier = 5.0f;
						moveSpeed *= multiplier;
						rotateSpeed *= multiplier;
					} 

					if (Input::IsKeyPressed(keyZero))
					{
						part->position = Vector2::zero;
						part->rotation = 0.0f;
						part->GetSprite()->position = Vector2::zero;
					}

					float moveAmount = Monocle::deltaTime * moveSpeed * 10.0f;
					float rotateAmount = Monocle::deltaTime * rotateSpeed;

					if (Input::IsKeyHeld(KEY_LCTRL))
					{
					}
					else
					{
						if (Input::IsKeyHeld(keyOffset))
						{
							if (part)
							{
								Sprite *sprite = part->GetSprite();

								if (Input::IsKeyHeld(keyMoveLeft))
									sprite->position += Vector2::left * moveAmount;
								if (Input::IsKeyHeld(keyMoveRight))
									sprite->position += Vector2::right * moveAmount;
								if (Input::IsKeyHeld(keyMoveUp))
									sprite->position += Vector2::up * moveAmount;
								if (Input::IsKeyHeld(keyMoveDown))
									sprite->position += Vector2::down * moveAmount;
							}
						}
						else
						{
							if (Input::IsKeyHeld(keyMoveLeft))
								Debug::selectedEntity->position += Vector2::left * moveAmount;
							if (Input::IsKeyHeld(keyMoveRight))
								Debug::selectedEntity->position += Vector2::right * moveAmount;
							if (Input::IsKeyHeld(keyMoveUp))
								Debug::selectedEntity->position += Vector2::up * moveAmount;
							if (Input::IsKeyHeld(keyMoveDown))
								Debug::selectedEntity->position += Vector2::down * moveAmount;
						}

						if (Input::IsKeyHeld(keyRotateLeft))
							Debug::selectedEntity->rotation -= rotateAmount;
						if (Input::IsKeyHeld(keyRotateRight))
							Debug::selectedEntity->rotation += rotateAmount;
					}


				}
				else 
				{

				}

				if (anim)
				{
					Part *part = dynamic_cast<Part*>(Debug::selectedEntity);

					if (Input::IsKeyPressed(keyBackwards))
						anim->AdjustCurrentTime(-TIME_STEP, false);
					if (Input::IsKeyPressed(keyForwards))
						anim->AdjustCurrentTime(TIME_STEP, false);

					if (Input::IsKeyPressed(keySetKeyFrame))
					{
						anim->SetPartKeyFrame(part, KeyFrame(anim->GetCurrentTime(), *part));
						//puppetEntity.puppet.GetCurrentAnimation()->AddNewPartKeyFrame();
					}
				}
			}
			else
			{
				//if (Input::IsMouseButtonHeld(MOUSE_BUTTON_LEFT))
				//puppetEntity->position = WEIGHTED_AVERAGE(puppetEntity->position, Input::GetWorldMousePosition(), 15);
			}
		}
	}
Пример #13
0
//------------------------------------------------------------------------------------------------
Person::Person(JQuad* quads[], JQuad* deadquad, std::vector<Bullet*>* bullets, std::vector<GunObject*>* guns, int team, char* name, int movementstyle)
{
	mRenderer = JRenderer::GetInstance();
	SetQuads(quads,deadquad);
	mX = 0.0f;
	mY = 0.0f;
	mOldX = 0.0f;
	mOldY = 0.0f;
	mWalkX = 0.0f;
	mWalkY = 0.0f;
	mSpeed = 0.0f;
	mAngle = 0.0f;
	mMaxSpeed = 0.0f;

	mMoveState = NOTMOVING;
	mState = DEAD;
	//mState = 0;
	mStateTime = 0.0f;
	mHealth = 100;
	mMoney = 800;
	mRecoilAngle = 0.0f;
	SetTotalRotation(M_PI_2);
	//mRotation = 0.0f;
	//mFacingAngle = M_PI_2;
	//mLastFireAngle = 0.0f;
	mTeam = team;
	strncpy(mName,name,25);
	mName[25] = '\0';
	mMovementStyle = movementstyle;
	mNumKills = 0;
	mNumDeaths = 0;
	mSoundId = -1;
	mNumDryFire = 0;
	/*mGuns[PRIMARY] = NULL;
	mGuns[SECONDARY] = NULL;
	mGuns[KNIFE] = NULL;
	mGuns[mGunIndex] = NULL;*/
	for (int i=0; i<5; i++) {
		mGuns[i] = NULL;
	}
	mGunIndex = KNIFE;

	mFadeTime = 0.0f;
	mStepTime = 0.0f;
	mIsActive = true;
	mBullets = bullets;
	mGunObjects = guns;

	mPing = 0.0f;
	mIsPlayerOnline = false;
	mIsFiring = false;
	mHasFired = false;

	mIsFlashed = false;
	mFlashTime = 0.0f;
	mFlashIntensity = 0.0f;

	mIsInBuyZone = false;

	mNode = NULL;
	mTargetNode = NULL;

	for (int i=0; i<10; i++) {
		mAnimations[i] = NULL;
	}

	for (int i=ANIM_PRIMARY; i<=ANIM_SECONDARY_RELOAD; i++) {
		mAnimations[i] = new Animation(gKeyFrameAnims[i],true,false);
	}

	mCurrentAnimation = mAnimations[1];

	mKeyFrame = KeyFrame();
	mKeyFrame.angles[BODY] = 0.4f;
	mKeyFrame.angles[RIGHTARM] = 0.0f;
	mKeyFrame.angles[RIGHTHAND] = 0.0f;
	mKeyFrame.angles[LEFTARM] = 0.0f;
	mKeyFrame.angles[LEFTHAND] = 0.0f;
	mKeyFrame.angles[GUN] = 0.0f;
	mKeyFrame.duration = 10;

	mWalkState = WALK1;
	mWalkTime = 0.0f;
	mWalkAngle = 0.0f;

	mMuzzleFlashIndex = 0;
	mMuzzleFlashAngle = 0.0f;
	mMuzzleFlashTime = 0.0f;

	mRadarTime = 0.0f;
	mRadarX = 0.0f;
	mRadarY = 0.0f;

	mHasFlag = false;

	mInvincibleTime = 0.0f;
	/*JTexture* texture = mRenderer->LoadTexture("gfx/playerparts.png");
	mPartQuads[BODY] = new JQuad(texture,0,0,32,16);
	mPartQuads[BODY]->SetHotSpot(16,8);

	mPartQuads[5] = new JQuad(texture,16,16,16,16);
	mPartQuads[5]->SetHotSpot(8,8);

	mPartQuads[RIGHTARM] = new JQuad(texture,0,16,16,8);
	mPartQuads[RIGHTARM]->SetHotSpot(4.5f,3.5f);

	mPartQuads[RIGHTHAND] = new JQuad(texture,0,24,16,8);
	mPartQuads[RIGHTHAND]->SetHotSpot(3.5f,3.5f);

	mPartQuads[LEFTARM] = new JQuad(texture,0,16,16,8);
	mPartQuads[LEFTARM]->SetHotSpot(4.5f,3.5f);
	mPartQuads[LEFTARM]->SetVFlip(true);

	mPartQuads[LEFTHAND] = new JQuad(texture,0,24,16,8);
	mPartQuads[LEFTHAND]->SetHotSpot(3.5f,3.5f);
	mPartQuads[LEFTHAND]->SetVFlip(true);*/
}
Пример #14
0
  void
  SVGAnimateElement::animationTraverse(svgl::AnimationInfo* animinfo)
  {
    unicode::String* attrName = GET_SIMPLE_VAL(AttributeName);
    SVG_ANIMATION_ATTRIBUTE_TYPE attrType = GET_SIMPLE_VAL(AttributeType);

    _elementToAnimate = animinfo->element;
    _attributeToAnimate=0;

    switch (attrType) {
    case SVG_ANIMATION_ATTRIBUTE_TYPE_CSS:
      std::cerr << "CSS animation not supported" << __FL__;
      return;
      break;

    default:
      attributeType.setValue(SVG_ANIMATION_ATTRIBUTE_TYPE_AUTO);
    case SVG_ANIMATION_ATTRIBUTE_TYPE_AUTO:
    case SVG_ANIMATION_ATTRIBUTE_TYPE_XML:
      {
      _attributeToAnimate = _elementToAnimate->getAttributeByName(attrName);
      }
      break;
#if 0
    default:
      std::cerr << "SVG_ANIMATION_ATTRIBUTE is set to UNKNOWN" << __FL__;
      break;
#endif
    }

    if(_attributeToAnimate==0) {
      if(css::CSSStyleDeclaration::isStyleAttribute(attrName)) {
	std::cerr << "attribute '" << attrName << "' for element '" << _elementToAnimate->getDtdElement() << "' is a style attribute and is not yet supported yet '<animate>'" << __FL__;
      }
      else {
	std::cerr << "attribute '" << attrName << "' does not exist for element " << _elementToAnimate->getDtdElement() << __FL__;
      }
      return;
    }

    if(!_attributeToAnimate->canBeSetAsDouble()) {
      _attributeToAnimate=0;
      std::cerr << "attribute '" << attrName << "' in element '" << _elementToAnimate->getDtdElement() << "' can not be set as double" << __FL__;
      return;
    }

    const SVGLengthList& values = GET_SIMPLE_VAL(Values);
#if 0
    std::cerr << "-- values" << __FL__;
    for(unsigned int t=0; t<values.size(); ++t)
      std::cerr << values[t] << " ";
    std::cerr << std::endl;
#endif
    if(values.numberOfItems()) {

      const SVGNumberList& keytimes = GET_SIMPLE_VAL(KeyTimes);
#if 0
      std::cerr << "** keytimes " << __FL__;
#endif
      if(keytimes.numberOfItems()) {
	if(keytimes.numberOfItems()!=values.numberOfItems()) {
	  std::cerr << "'keyTimes' and 'values' have different size" << __FL__;
	  return;
	}
	for(std::vector<float>::size_type i=0;
	    i<values.numberOfItems();
	    ++i) {
	  SVGLength l = values.getItem(i);
	  float v = l.computeValue();
	  _keyFrames.push_back(KeyFrame(v, keytimes.getItem(i).GET_SIMPLE_VAL(Value)));
	  //	  std::cerr << values[i] << " " << keytimes[i];
	}
	//	std::cerr << std::endl;

      }
      else {
	for(std::vector<float>::size_type i=0;
	    i<values.numberOfItems();
	    ++i) {
	  float t=i/((float)values.numberOfItems()-1);
	  SVGLength l = values.getItem(i);
	  float v = l.computeValue();
	  _keyFrames.push_back(KeyFrame(v, t));
	}
      }
      
    }
    else {
      unicode::String* fromstr = GET_SIMPLE_VAL(From);
      unicode::String* tostr = GET_SIMPLE_VAL(To);
      unicode::String* bystr = GET_SIMPLE_VAL(By);
      //std::cerr << DBGVAR(attrName) << DBGVAR(attrType) << DBGVAR(fromstr) << DBGVAR(tostr) << __FL__;

      SVGLength froml, tol, byl;
      bool fromb=false, tob=false, byb=false;

      froml.dom_setValueAsString(fromstr);
      tol.dom_setValueAsString(tostr);
      byl.dom_setValueAsString(bystr);

      fromb = (froml.GET_SIMPLE_VAL(UnitType) != SVGLength::SVG_LENGTHTYPE_UNKNOWN);
      tob = (tol.GET_SIMPLE_VAL(UnitType) != SVGLength::SVG_LENGTHTYPE_UNKNOWN);
      byb = (byl.GET_SIMPLE_VAL(UnitType) != SVGLength::SVG_LENGTHTYPE_UNKNOWN);

    float from = froml.GET_SIMPLE_VAL(Value);
      float to = tol.GET_SIMPLE_VAL(Value);
      float by = byl.GET_SIMPLE_VAL(Value);

    // std::cerr << DBGVAR(fromb) << DBGVAR(tob) << DBGVAR(byb) << __FL__;

      if( !(fromb||tob||byb) ) {
	std::cerr << "'from', 'to' and 'by' are unset" << __FL__;
	return;
      }

      // FIXME
      // from is not computed with right dpi...
      if(!fromb) {
	fromb=true;
	from = _attributeToAnimate->getBaseVal();
      }
      if(!tob) {
	if(byb) {
	  to=from+by;
	}
	else {
	  STDDBG;
	  return;
	}
      }

      if(fromb)
	_keyFrames.push_back(KeyFrame(from, 0));
      _keyFrames.push_back(KeyFrame(to, 1));

    }

#if 0
    DBG;
    for(unsigned int j=0; j<_keyFrames.numberOfItems(); ++j) {
      std::cerr << "(" << _keyFrames[j].value << "," << _keyFrames[j].time << ")";
    }
    std::cerr << std::endl;
#endif

    SVGAnimationElement::animationTraverse(animinfo);

  }
Пример #15
0
  void
  SVGAnimateElement::tick(svgl::Animation::TickInfo* tickinfo)
  {

    if(!_attributeToAnimate) {
      std::cerr << "no attribute to animate" << __FL__;
      return;
    }

    if(!tickinfo->dur) {
      std::cerr << "invalid tickinfo->dur " << tickinfo->dur << __FL__;
    }

    float timeRatio = (tickinfo->totalElapsed/(float)tickinfo->dur);

    if(_keyFrames.size()==0 ) {
      // from is not set
      // not very reliable FIXME
      std::cerr << "invalid attribute 'keyTimes'" << __FL__;
      return;
    }

#if 0
    if(_keyFrames.size()==1 ) {
      // from is not set
      // not very reliable FIXME
      double from = _attributeToAnimate->getBaseVal(); // now it has been computed
      KeyFrame toframe = _keyFrames[0];
      _keyFrames[0]=KeyFrame(from, 0);
      _keyFrames.push_back(toframe);
    }
#endif

    std::vector<float>::size_type i=0;
    for(;
	i<_keyFrames.size();
	++i) {
      if( _keyFrames[i].time>=timeRatio) {	
	break;
      }
    }

    // if the first one is non-zero
    // is it possible ??
    if(i==0)
      return;

    float from = _keyFrames[i-1].value;
    float to = _keyFrames[i].value;
    
    timeRatio -= _keyFrames[i-1].time;

    double newvalue;
    float deltatime = _keyFrames[i].time -_keyFrames[i-1].time;
    if(deltatime<=.00001)
      newvalue=to;
    else {
      timeRatio /= deltatime;
      newvalue = from + (to-from)*timeRatio;
    }
      
    // std::cerr << DBGVAR(from) << DBGVAR(to) << DBGVAR(newvalue) << DBGVAR(deltatime) << __FL__;

    _attributeToAnimate->setAsDouble(newvalue);
  }