コード例 #1
0
		void ObjectController::SetPosition( const Float3& vPos)
		{
			SceneNode* pNode	=	GetParentSceneNode();
			if(pNode!=NULL){
				pNode->SetPosition(vPos);
				static Float44 matWorld;
				static Float4  rot;
				static Float3  scale;
				pNode->Update(matWorld,rot,scale,false);
			}
		}
コード例 #2
0
ファイル: Lesson1.cpp プロジェクト: smalice/Cap3DDemo
int DrawGLScene(GLvoid)									// Here's Where We Do All The Drawing
{
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);	// Clear Screen And Depth Buffer
	glLoadIdentity();
	
	// Reset The Current Modelview Matrix


	glMatrixMode(GL_MODELVIEW);							// Select The Modelview Matrix
	glLoadIdentity();	
	// Reset The Modelview Matrix
	gluLookAt(cameraX, cameraY, cameraZ,  //eye
		      cameraCX,cameraCY,cameraCZ, //center
			  0.0f,0.0f,1.0f);//up

	double now = currentTime();
	sceneroot.Update(now - lastframetime);
	sceneroot.Render();
	lastframetime = now;


	return TRUE;										// Everything Went OK
}
コード例 #3
0
ファイル: Branch.cpp プロジェクト: JohnEz/Dissertation
void Branch::Update(float msec)
{
	mesh->Update(msec);

	SceneNode::Update(msec);

	if (mesh->GetDrawIndices() == (branchSize * 24) && numLeafs < maxLeafs)
	{

		SceneNode* leaf = new SceneNode(sphere);

		float leafpos = (float)((mesh->GetDrawIndices() / 24) / 5);
		leaf->SetTransform(Matrix4::Translation(Vector3(0, leafpos * maxScale.y, 0)));
		leaf->SetModelScale(Vector3(20,20,20));

		AddChild(leaf);

		leaf->Update(msec);

		///////
		PhysicsNode*p = new PhysicsNode();

		float elements[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1};
		Matrix4 mat = Matrix4(elements);
		p->SetInverseInertia(mat);
		p->SetUseGravity(false);
		p->SetInverseMass(0.0f);

		p->SetPosition(leaf->GetWorldTransform().GetPositionVector());

		p->SetCollisionVolume(new CollisionLeaf(20));

		Vector3 startPos = GetWorldTransform().GetPositionVector();
		Vector3 endPos = leaf->GetWorldTransform().GetPositionVector();

		PhysicsSystem::GetPhysicsSystem().AddNode(p);

		/////////

		Light l = Light();

		l.SetPosition(leaf->GetWorldTransform().GetPositionVector());

		l.SetColour(Vector4 (0, 1, 0, 1.0f));

		l.SetRadius(150);

		LightStorage::GetInstance()->addLight(l);

		numLeafs++;

	}

	if (modelScale.x < maxScale.x)
	{
		modelScale.x += 0.000001;
		modelScale.z += 0.000001;
	}

	if (!hasPhysics && GetWorldTransform().GetPositionVector().Length() != 0)
	{

		SceneNode* leaf = new SceneNode(sphere);

		float leafpos = (float)((mesh->getNumInd() / 24) / 5);
		leaf->SetTransform(Matrix4::Translation(Vector3(0, leafpos * maxScale.y, 0)));

		AddChild(leaf);

		leaf->Update(msec);

		///////
		PhysicsNode*p = new PhysicsNode();

		float elements[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1};
		Matrix4 mat = Matrix4(elements);
		p->SetInverseInertia(mat);
		p->SetUseGravity(false);
		p->SetInverseMass(0.0f);

		p->SetPosition(leaf->GetWorldTransform().GetPositionVector());

		Vector3 startPos = GetWorldTransform().GetPositionVector();
		Vector3 endPos = leaf->GetWorldTransform().GetPositionVector();

		endBranch = endPos;

		p->SetCollisionVolume(new CollisionCylinder(1, startPos, endPos));

		myNode = p;

		PhysicsSystem::GetPhysicsSystem().AddNode(p);

		/////////

		hasPhysics = true;
		RemoveChild(leaf);
	}

	if (myNode)
	{
		float v = mesh->GetDrawIndices();
		float z = v / (branchSize * 24);
		Vector3 posDif = endBranch - GetWorldTransform().GetPositionVector();
		Vector3 endPos = GetWorldTransform().GetPositionVector() + (posDif * z);

		myNode->SetCollisionVolume(new CollisionCylinder(2, GetWorldTransform().GetPositionVector(), endPos));
	}

}