void MyGame::CreateSphereToCameraPosition()
{
	SceneNode* s = new SceneNode(sphere);
	s->SetRotation(Matrix4::Translation(gameCamera->GetPosition()));
	//s->SetTranslation(Vector3());

	s->SetModelScale(Vector3(SPHERE_INITIAL_SIZE * sizeFactor, SPHERE_INITIAL_SIZE * sizeFactor, SPHERE_INITIAL_SIZE * sizeFactor));
	//s->SetModelScale(Vector3(1000.0f, 1000.0f , 1000.0f));

	s->SetBoundingRadius(SPHERE_INITIAL_SIZE * sizeFactor);
	s->SetColour(Vector4((((int)rand()) % 100) / 100.0f, (((int)rand()) % 100) / 100.0f, (((int)rand()) % 100) / 100.0f, 1.0f));

	GameEntity*g = new GameEntity(s, new SpherePhysicsNode());
	((SpherePhysicsNode&)(g->GetPhysicsNode())).SetRadius(SPHERE_INITIAL_SIZE*sizeFactor);

	g->GetPhysicsNode().SetPosition(gameCamera->GetPosition());

	cout << "sphere created on position " << gameCamera->GetPosition() << endl;

	g->GetPhysicsNode().SetInvMass(SPHERE_INITIAL_INVMASS / sizeFactor);
	Vector3 speedVec = gameCamera->GetViewVector();
	speedVec = speedVec * SPHERE_INITIAL_SPEED * (const float)speedFactor;
	g->GetPhysicsNode().SetLinearVelocity(speedVec);
	g->GetPhysicsNode().SetGravityFactor(EARTH_GRAVITY_FACTOR);
	g->GetPhysicsNode().ActivateNode();

	g->GetPhysicsNode().BuildInertiaMatrix();
	g->ConnectToSystems();
	allEntities.push_back(g);
}
Esempio n. 2
0
int playstate::Component_SetNodeRotation(lua_State* L)
{
    if(lua_gettop(L) < 2) {
        luaM_printerror(L, "Expected: self<Component>:SetNodeRotation(Vector3)");
        luaM_pushvector3(L, Vector3::Zero);
        return 1;
    }

    Vector3 vec = luaM_popvector3(L);
    ScriptableComponent* component = luaM_popobject<ScriptableComponent>(L);
    if(component != NULL) {
        SceneNode* owner = component->GetNode();
        owner->SetRotation(vec);
    }

    return 0;
}
/*
Makes a sphere.
*/
GameEntity* MyGame::BuildSphereEntity(float radius, const Vector3& position) {
	SceneNode* s = new SceneNode(sphere);

	s->SetRotation(Matrix4::Translation(position));

	s->SetModelScale(Vector3(radius,radius,radius));
	s->SetBoundingRadius(radius);

	GameEntity*g = new GameEntity(s, new SpherePhysicsNode());
	((SpherePhysicsNode&)(g->GetPhysicsNode())).SetRadius(radius);
	g->GetPhysicsNode().SetPosition(position);
	g->GetPhysicsNode().SetGravityFactor(EARTH_GRAVITY_FACTOR);
	float massFactor = radius / SPHERE_INITIAL_SIZE;
	g->GetPhysicsNode().SetInvMass(SPHERE_INITIAL_INVMASS / massFactor);
	g->GetPhysicsNode().ActivateNode();
	g->GetPhysicsNode().BuildInertiaMatrix();
	g->ConnectToSystems();
	return g;
}
void MyGame::BuildDodgingEntities(float size, Vector3& initialPosition)
{
	SceneNode* s = new SceneNode(sphere);

	s->SetColour(Vector4(1.0f, 1.0f, 1.0f, 1.0f));

	s->SetRotation(Matrix4::Translation(initialPosition));

	s->SetModelScale(Vector3(size, size, size));
	s->SetBoundingRadius(size);
	
	SpherePhysicsNode* g = new SpherePhysicsNode();
	g->SetRadius(size);
	g->SetPosition(initialPosition);
	g->SetGravityFactor(NON_GRAVITY);
	float massFactor = size / SPHERE_INITIAL_SIZE;
	g->SetInvMass(SPHERE_INITIAL_INVMASS / massFactor);
	g->ActivateNode();
	g->BuildInertiaMatrix();
	g->SetTarget(s);
	g->dumpingFactor = 0.9f;
	Renderer::GetRenderer().AddNode(s);
	PhysicsSystem::GetPhysicsSystem().SetDodgingEntity(g);
}