GL - i think this is working, not using the lvl loader. put models in /Content/Models and /textures

This commit is contained in:
lindaandersson 2014-02-10 16:28:25 +01:00
commit bfb763501d
7 changed files with 139 additions and 133 deletions

View File

@ -76,11 +76,107 @@ GameState::gameStateState GameState::LoadGame()
plight.Bright = 2; plight.Bright = 2;
Oyster::Graphics::API::AddLight(plight); Oyster::Graphics::API::AddLight(plight);
LoadModels("3bana.bias"); // use level loader
//LoadModels("3bana.bias");
// hardcoded objects
LoadModels();
Float3 startPos = Float3(0,0,20.0f); Float3 startPos = Float3(0,0,20.0f);
InitCamera(startPos); InitCamera(startPos);
return gameStateState_playing; return gameStateState_playing;
} }
bool GameState::LoadModels()
{
// open file
// read file
// init models
int nrOfBoxex = 5;
int id = 100;
// add world model
ModelInitData modelData;
modelData.position = Oyster::Math::Float3(0,0,0);
modelData.rotation = Oyster::Math::Quaternion::identity;
modelData.scale = Oyster::Math::Float3(2,2,2);
modelData.modelPath = L"world_earth.dan";
modelData.id = id++;
this->staticObjects.Push(new C_StaticObj());
this->staticObjects[this->staticObjects.Size() -1 ]->Init(modelData);
// add box model
modelData.position = Oyster::Math::Float3(0,0,0);
modelData.rotation = Oyster::Math::Quaternion::identity;
modelData.scale = Oyster::Math::Float3(1,1,1);
modelData.modelPath = L"crate_colonists.dan";
for(int i =0; i< nrOfBoxex; i ++)
{
modelData.position = Oyster::Math::Float3(4,320,0);
modelData.id = id++;
this->dynamicObjects.Push(new C_DynamicObj());
this->dynamicObjects[this->dynamicObjects.Size() -1 ]->Init(modelData);
}
// add crystal model
modelData.position = Oyster::Math::Float3(10, 301, 0);
modelData.modelPath = L"crystalformation_b.dan";
modelData.id = id++;
// load models
this->dynamicObjects.Push(new C_DynamicObj());
this->dynamicObjects[this->dynamicObjects.Size() -1 ]->Init(modelData);
// add house model
modelData.position = Oyster::Math::Float3(-50, 290, 0);
//Oyster::Math3D::Float4x4 rot = Oyster::Math3D::RotationMatrix(Oyster::Math::Float3(0 ,Utility::Value::Radian(90.0f), 0));
modelData.visible = true;
modelData.modelPath = L"building_corporation.dan";
modelData.id = id++;
// load models
this->dynamicObjects.Push(new C_DynamicObj());
this->dynamicObjects[this->dynamicObjects.Size() -1 ]->Init(modelData);
// add player model
modelData.position = Oyster::Math::Float3(0, 320, 0);
modelData.modelPath = L"char_still_sizeref.dan";
modelData.id = id++;
// load models
this->dynamicObjects.Push(new C_DynamicObj());
this->dynamicObjects[this->dynamicObjects.Size() -1 ]->Init(modelData);
// add player model 2
modelData.position = Oyster::Math::Float3(50, 320, 0);
modelData.modelPath = L"char_still_sizeref.dan";
modelData.id = id++;
// load models
this->dynamicObjects.Push(new C_DynamicObj());
this->dynamicObjects[this->dynamicObjects.Size() -1 ]->Init(modelData);
// add jumppad
modelData.position = Oyster::Math::Float3(4, 300.3, 0);
modelData.modelPath = L"jumppad_round.dan";
modelData.id = id++;
// load models
this->dynamicObjects.Push(new C_DynamicObj());
this->dynamicObjects[this->dynamicObjects.Size() -1 ]->Init(modelData);
// add sky sphere
modelData.position = Oyster::Math::Float3(0,0,0);
modelData.scale = Oyster::Math::Float3(800,800,800);
modelData.modelPath = L"skysphere.dan";
modelData.id = id++;
// load models
this->dynamicObjects.Push(new C_DynamicObj());
this->dynamicObjects[this->dynamicObjects.Size() -1 ]->Init(modelData);
return true;
}
bool GameState::LoadModels(std::string mapFile) bool GameState::LoadModels(std::string mapFile)
{ {
GameLogic::LevelLoader levelLoader; GameLogic::LevelLoader levelLoader;
@ -166,129 +262,6 @@ bool GameState::LoadModels(std::string mapFile)
privData->object[privData->object.size() -1 ]->Init(modelData); privData->object[privData->object.size() -1 ]->Init(modelData);
*/ */
return true; return true;
/*// open file
// read file
// init models
int nrOfBoxex = 5;
int id = 100;
// add world model
ModelInitData modelData;
Oyster::Math3D::Float4x4 translate;
C_Object* obj;
translate = Oyster::Math3D::TranslationMatrix(Oyster::Math::Float3(0,0,0));
modelData.world = translate ;//modelData.world * translate
modelData.world.v[0].x = 2;
modelData.world.v[1].y = 2;
modelData.world.v[2].z = 2;
modelData.modelPath = L"world_earth.dan";
modelData.id = id++;
obj = new C_Player();
privData->object.push_back(obj);
privData->object[privData->object.size() -1 ]->Init(modelData);
// add box model
modelData.world = Oyster::Math3D::Float4x4::identity;
modelData.modelPath = L"crate_colonists.dan";
for(int i =0; i< nrOfBoxex; i ++)
{
translate = Oyster::Math3D::TranslationMatrix(Oyster::Math::Float3(4,320,0));
modelData.world = modelData.world * translate;
modelData.id = id++;
obj = new C_Player();
privData->object.push_back(obj);
privData->object[privData->object.size() -1 ]->Init(modelData);
modelData.world = Oyster::Math3D::Float4x4::identity;
}
// add crystal model
modelData.world = Oyster::Math3D::Float4x4::identity;
translate = Oyster::Math3D::TranslationMatrix(Oyster::Math::Float3(10, 301, 0));
modelData.world = modelData.world * translate;
modelData.visible = true;
modelData.modelPath = L"crystalformation_b.dan";
modelData.id = id++;
// load models
obj = new C_Player();
privData->object.push_back(obj);
privData->object[privData->object.size() -1 ]->Init(modelData);
// add house model
modelData.world = Oyster::Math3D::Float4x4::identity;
translate = Oyster::Math3D::TranslationMatrix(Oyster::Math::Float3(-50, 290, 0));
Oyster::Math3D::Float4x4 rot = Oyster::Math3D::RotationMatrix(Oyster::Math::Float3(0 ,Utility::Value::Radian(90.0f), 0));
modelData.world = modelData.world * translate * rot;
modelData.visible = true;
modelData.modelPath = L"building_corporation.dan";
modelData.id = id++;
// load models
obj = new C_Player();
privData->object.push_back(obj);
privData->object[privData->object.size() -1 ]->Init(modelData);
// add player model
modelData.world = Oyster::Math3D::Float4x4::identity;
translate = Oyster::Math3D::TranslationMatrix(Oyster::Math::Float3(0, 320, 0));
modelData.world = modelData.world * translate;
modelData.visible = true;
modelData.modelPath = L"char_still_sizeref.dan";
modelData.id = id++;
// load models
obj = new C_Player();
privData->object.push_back(obj);
privData->object[privData->object.size() -1 ]->Init(modelData);
// add player model 2
modelData.world = Oyster::Math3D::Float4x4::identity;
translate = Oyster::Math3D::TranslationMatrix(Oyster::Math::Float3(50, 320, 0));
modelData.world = modelData.world * translate;
modelData.visible = true;
modelData.modelPath = L"char_still_sizeref.dan";
modelData.id = id++;
// load models
obj = new C_Player();
privData->object.push_back(obj);
privData->object[privData->object.size() -1 ]->Init(modelData);
// add jumppad
modelData.world = Oyster::Math3D::Float4x4::identity;
translate = Oyster::Math3D::TranslationMatrix(Oyster::Math::Float3(4, 300.3, 0));
//Oyster::Math3D::RotationMatrix_AxisZ()
modelData.world = modelData.world * translate;
modelData.visible = true;
modelData.modelPath = L"jumppad_round.dan";
modelData.id = id++;
// load models
obj = new C_Player();
privData->object.push_back(obj);
privData->object[privData->object.size() -1 ]->Init(modelData);
// add sky sphere
modelData.world = Oyster::Math3D::Float4x4::identity;
translate = Oyster::Math3D::TranslationMatrix(Oyster::Math::Float3(0, 0, 0));
//Oyster::Math3D::RotationMatrix_AxisZ()
modelData.world = modelData.world * translate;
modelData.world.v[0].x = 800;
modelData.world.v[1].y = 800;
modelData.world.v[2].z = 800;
modelData.visible = true;
modelData.modelPath = L"skysphere.dan";
modelData.id = id++;
// load models
obj = new C_Player();
privData->object.push_back(obj);
privData->object[privData->object.size() -1 ]->Init(modelData); */
} }
bool GameState::InitCamera(Float3 startPos) bool GameState::InitCamera(Float3 startPos)

View File

@ -44,6 +44,7 @@ public:
bool Init(Oyster::Network::NetworkClient* nwClient); bool Init(Oyster::Network::NetworkClient* nwClient);
GameClientState::ClientState Update(float deltaTime, InputClass* KeyInput) override; GameClientState::ClientState Update(float deltaTime, InputClass* KeyInput) override;
bool LoadModels(std::string mapFile); bool LoadModels(std::string mapFile);
bool LoadModels();
bool InitCamera(Oyster::Math::Float3 startPos) ; bool InitCamera(Oyster::Math::Float3 startPos) ;
void InitiatePlayer(int id, std::wstring modelName, Oyster::Math::Float4x4 world); void InitiatePlayer(int id, std::wstring modelName, Oyster::Math::Float4x4 world);
gameStateState LoadGame(); gameStateState LoadGame();

View File

@ -40,7 +40,7 @@ void Level::parseObjectType(ObjectTypeHeader* obj)
break; break;
}*/ }*/
} }
void Level::parsePhysicsObj(LevelLoaderInternal::PhysicsObject* obj) void Level::parsePhysicsObj(LevelLoaderInternal::BoundingVolumeBase* obj)
{ {
// offset physObj med modelObj // offset physObj med modelObj
} }
@ -68,7 +68,7 @@ void Level::InitiateLevel(std::string levelPath)
{ {
ObjectHeader* staticObjData = ((ObjectHeader*)obj); ObjectHeader* staticObjData = ((ObjectHeader*)obj);
LevelLoaderInternal::PhysicsObject* staticObjPhysicData = ((ObjectHeader*)obj); //LevelLoaderInternal::BoundingVolumeBase* staticObjPhysicData = ((ObjectHeader*)obj);
staticObjData->ModelFile; staticObjData->ModelFile;
ICustomBody* rigidBody_Static; ICustomBody* rigidBody_Static;
@ -132,7 +132,7 @@ void Level::InitiateLevel(std::string levelPath)
case ObjectType::ObjectType_Dynamic: case ObjectType::ObjectType_Dynamic:
{ {
ObjectHeader* staticObjData = ((ObjectHeader*)obj); ObjectHeader* staticObjData = ((ObjectHeader*)obj);
LevelLoaderInternal::PhysicsObject* staticObjPhysicData = ((ObjectHeader*)obj); //LevelLoaderInternal::BoundingVolumeBase* staticObjPhysicData = ((ObjectHeader*)obj);
staticObjData->ModelFile; staticObjData->ModelFile;
ICustomBody* rigidBody_Dynamic; ICustomBody* rigidBody_Dynamic;

View File

@ -33,7 +33,7 @@ namespace GameLogic
void InitiateLevel(float radius); void InitiateLevel(float radius);
void parseObjectType(ObjectTypeHeader* obj); void parseObjectType(ObjectTypeHeader* obj);
void parsePhysicsObj(LevelLoaderInternal::PhysicsObject* obj); void parsePhysicsObj(LevelLoaderInternal::BoundingVolumeBase* obj);
/******************************************************** /********************************************************
* Creates a team in the level * Creates a team in the level
* @param teamSize: The size of the team you want to create * @param teamSize: The size of the team you want to create

View File

@ -50,6 +50,7 @@ API_Impl::~API_Impl()
ICustomBody* API_Impl::AddCollisionSphere(float radius, ::Oyster::Math::Float4 rotation, ::Oyster::Math::Float3 position, float mass, float restitution, float staticFriction, float dynamicFriction) ICustomBody* API_Impl::AddCollisionSphere(float radius, ::Oyster::Math::Float4 rotation, ::Oyster::Math::Float3 position, float mass, float restitution, float staticFriction, float dynamicFriction)
{ {
SimpleRigidBody* body = new SimpleRigidBody; SimpleRigidBody* body = new SimpleRigidBody;
SimpleRigidBody::State state;
// Add collision shape // Add collision shape
btCollisionShape* collisionShape = new btSphereShape(radius); btCollisionShape* collisionShape = new btSphereShape(radius);
@ -73,12 +74,22 @@ ICustomBody* API_Impl::AddCollisionSphere(float radius, ::Oyster::Math::Float4 r
this->dynamicsWorld->addRigidBody(rigidBody); this->dynamicsWorld->addRigidBody(rigidBody);
this->customBodies.push_back(body); this->customBodies.push_back(body);
state.centerPos = position;
state.reach = Float3(radius, radius, radius);
state.dynamicFrictionCoeff = 0.5f;
state.staticFrictionCoeff = 0.5f;
state.quaternion = Quaternion(Float3(rotation.xyz), rotation.w);
state.mass = mass;
body->SetState(state);
return body; return body;
} }
ICustomBody* API_Impl::AddCollisionBox(Float3 halfSize, ::Oyster::Math::Float4 rotation, ::Oyster::Math::Float3 position, float mass, float restitution, float staticFriction, float dynamicFriction) ICustomBody* API_Impl::AddCollisionBox(Float3 halfSize, ::Oyster::Math::Float4 rotation, ::Oyster::Math::Float3 position, float mass, float restitution, float staticFriction, float dynamicFriction)
{ {
SimpleRigidBody* body = new SimpleRigidBody; SimpleRigidBody* body = new SimpleRigidBody;
SimpleRigidBody::State state;
// Add collision shape // Add collision shape
btCollisionShape* collisionShape = new btBoxShape(btVector3(halfSize.x, halfSize.y, halfSize.z)); btCollisionShape* collisionShape = new btBoxShape(btVector3(halfSize.x, halfSize.y, halfSize.z));
@ -102,12 +113,22 @@ ICustomBody* API_Impl::AddCollisionBox(Float3 halfSize, ::Oyster::Math::Float4 r
this->dynamicsWorld->addRigidBody(rigidBody); this->dynamicsWorld->addRigidBody(rigidBody);
this->customBodies.push_back(body); this->customBodies.push_back(body);
state.centerPos = position;
state.reach = halfSize;
state.dynamicFrictionCoeff = 0.5f;
state.staticFrictionCoeff = 0.5f;
state.quaternion = Quaternion(Float3(rotation.xyz), rotation.w);
state.mass = mass;
body->SetState(state);
return body; return body;
} }
ICustomBody* API_Impl::AddCollisionCylinder(::Oyster::Math::Float3 halfSize, ::Oyster::Math::Float4 rotation, ::Oyster::Math::Float3 position, float mass, float restitution, float staticFriction, float dynamicFriction) ICustomBody* API_Impl::AddCollisionCylinder(::Oyster::Math::Float3 halfSize, ::Oyster::Math::Float4 rotation, ::Oyster::Math::Float3 position, float mass, float restitution, float staticFriction, float dynamicFriction)
{ {
SimpleRigidBody* body = new SimpleRigidBody; SimpleRigidBody* body = new SimpleRigidBody;
SimpleRigidBody::State state;
// Add collision shape // Add collision shape
btCollisionShape* collisionShape = new btCylinderShape(btVector3(halfSize.x, halfSize.y, halfSize.z)); btCollisionShape* collisionShape = new btCylinderShape(btVector3(halfSize.x, halfSize.y, halfSize.z));
@ -131,6 +152,15 @@ ICustomBody* API_Impl::AddCollisionCylinder(::Oyster::Math::Float3 halfSize, ::O
this->dynamicsWorld->addRigidBody(rigidBody); this->dynamicsWorld->addRigidBody(rigidBody);
this->customBodies.push_back(body); this->customBodies.push_back(body);
state.centerPos = position;
state.reach = halfSize;
state.dynamicFrictionCoeff = 0.5f;
state.staticFrictionCoeff = 0.5f;
state.quaternion = Quaternion(Float3(rotation.xyz), rotation.w);
state.mass = mass;
body->SetState(state);
return body; return body;
} }

View File

@ -52,9 +52,11 @@ SimpleRigidBody::State& SimpleRigidBody::GetState( SimpleRigidBody::State &targe
void SimpleRigidBody::SetState( const SimpleRigidBody::State &state ) void SimpleRigidBody::SetState( const SimpleRigidBody::State &state )
{ {
btTransform trans; btTransform trans;
btVector3 position(state.centerPos.x, state.centerPos.y, state.centerPos.z);
btQuaternion quaternion(state.quaternion.imaginary.x, state.quaternion.imaginary.y, state.quaternion.imaginary.z, state.quaternion.real);
this->motionState->getWorldTransform(trans); this->motionState->getWorldTransform(trans);
trans.setRotation(btQuaternion(state.quaternion.imaginary.x, state.quaternion.imaginary.y, state.quaternion.imaginary.z, state.quaternion.real)); trans.setRotation(quaternion);
trans.setOrigin(btVector3(state.centerPos.x, state.centerPos.y, state.centerPos.z)); trans.setOrigin(position);
this->motionState->setWorldTransform(trans); this->motionState->setWorldTransform(trans);
this->rigidBody->setFriction(state.staticFrictionCoeff); this->rigidBody->setFriction(state.staticFrictionCoeff);
this->rigidBody->setRestitution(state.restitutionCoeff); this->rigidBody->setRestitution(state.restitutionCoeff);
@ -154,7 +156,7 @@ Float4x4 SimpleRigidBody::GetView( const ::Oyster::Math::Float3 &offset ) const
void SimpleRigidBody::CallSubscription_AfterCollisionResponse(ICustomBody* bodyA, ICustomBody* bodyB, Oyster::Math::Float kineticEnergyLoss) void SimpleRigidBody::CallSubscription_AfterCollisionResponse(ICustomBody* bodyA, ICustomBody* bodyB, Oyster::Math::Float kineticEnergyLoss)
{ {
if(this->onMovement) if(this->afterCollision)
this->afterCollision(bodyA, bodyB, kineticEnergyLoss); this->afterCollision(bodyA, bodyB, kineticEnergyLoss);
} }

View File

@ -16,7 +16,7 @@ namespace Oyster
public: public:
// Default constructor // Default constructor
CustomBodyState( ::Oyster::Math::Float mass = 1.0f, CustomBodyState( ::Oyster::Math::Float mass = 1.0f,
::Oyster::Math::Float restitutionCoeff = 1.0f, ::Oyster::Math::Float restitutionCoeff = 0.5f,
::Oyster::Math::Float staticFrictionCoeff = 1.0f, ::Oyster::Math::Float staticFrictionCoeff = 1.0f,
::Oyster::Math::Float dynamicFrictionCoeff = 1.0f, ::Oyster::Math::Float dynamicFrictionCoeff = 1.0f,
const ::Oyster::Math::Float3 &centerPos = ::Oyster::Math::Float3::null, const ::Oyster::Math::Float3 &centerPos = ::Oyster::Math::Float3::null,