void LoadTetrahedraCube(DemoEntityManager* const scene, int materialID)
	{
		dFloat mass = 5.0f;
		NewtonWorld* const world = scene->GetNewton();

		char name[2048];
		dGetWorkingFileName ("box.tet", name);
		NewtonMesh* const tetraCube = NewtonMeshLoadTetrahedraMesh(scene->GetNewton(), name);

		dMatrix aligmentUV(dGetIdentityMatrix());
		int material = LoadTexture("smilli.tga");
		NewtonMeshApplyBoxMapping(tetraCube, material, material, material, &aligmentUV[0][0]);
		NewtonMeshCalculateVertexNormals(tetraCube, 60.0f * dDegreeToRad);

		// make a deformable collision mesh
		NewtonCollision* const deformableCollision = NewtonCreateDeformableSolid(world, tetraCube, materialID);

		//create a rigid body with a deformable mesh
		m_body = CreateRigidBody(scene, mass, deformableCollision);

		// create the soft body mesh
		//m_mesh = new TetrahedraSoftMesh(tetraCube, m_body);
		DemoMesh* const mesh = new TetrahedraSoftMesh(scene, tetraCube, m_body);
		SetMesh(mesh, dGetIdentityMatrix());

		// do not forget to destroy this objects, else you get bad memory leaks.
		mesh->Release ();
		NewtonDestroyCollision(deformableCollision);
		NewtonMeshDestroy(tetraCube);
	}
void dMeshNodeInfo::ReplaceMesh (NewtonMesh* const mesh)
{
	if (m_mesh) {
		NewtonMeshDestroy(m_mesh);
	}
	SetMesh (mesh);
}
    EditorCamera::EditorCamera(const std::string& name)
        : EditorSceneNode(name)
    {
        SetMesh(Mesh::GetOrCreate<QuadMesh>("NSGEditorCamera"));
        SetMaterial(Material::GetOrCreate("NSGEditorCamera"));
        material_->SetRenderPass(RenderPass::TEXT);
		material_->SetDiffuseColor(COLOR_DODGER_BLUE);
        material_->EnableTransparent(true);
		material_->SetAlpha(0.9f);
        material_->SetBillboardType(BillboardType::SPHERICAL);
        material_->CastShadow(false);
        material_->ReceiveShadows(false);
		
		const int SIZE = 8;
		static const unsigned char image[SIZE][SIZE]
        {
            {X X X X X X X X},
            {X O O O O O O X},
            {X O X X X X O X},
            {X O X O O O O X},
            {X O X O O O O X},
            {X O X X X X O X},
            {X O O O O O O X},
            {X X X X X X X X},
        };

		auto texture = std::make_shared<Texture2D>();
		texture->SetFormat(GL_ALPHA);
		texture->SetData(&image[0][0]);
		texture->SetSize(SIZE, SIZE);
		texture->SetMapType(TextureType::COL);
		material_->SetTextMap(texture);
		texture->SetFilterMode(TextureFilterMode::NEAREST);
    }
Exemple #4
0
void
C_Chair::Spawn( )
{
	C_BaseEntity::Spawn();

	SetMesh( MaterialAPI()->GetOrLoadMesh( "chair" ) );
}
	void BuildRegularTetrahedra (DemoEntityManager* const scene, int materialID)
	{
		dFloat mass = 5.0f;
		NewtonWorld* const world = scene->GetNewton();

		dVector tetra[] = { dVector(-1.0f, 0.0f, -0.71f, 0.0f),
							dVector(1.0f, 0.0f, -0.71f, 0.0f),
							dVector(0.0f, -1.0f, 0.71f, 0.0f),
							dVector(0.0f, 1.0f, 0.71f, 0.0f) };

		NewtonMesh* const tetrahedra = NewtonMeshCreate(scene->GetNewton());
		NewtonMeshBeginBuild(tetrahedra);
			AddTetra (tetrahedra, 0, 1, 2, 3, tetra, 0);
		NewtonMeshEndBuild(tetrahedra);

		dMatrix aligmentUV(dGetIdentityMatrix());
		int material = LoadTexture("smilli.tga");
		NewtonMeshApplyBoxMapping (tetrahedra, material, material, material, &aligmentUV[0][0]);
		NewtonMeshCalculateVertexNormals (tetrahedra, 60.0f * dDegreeToRad);

		// make a deformable collision mesh
		NewtonCollision* const deformableCollision = NewtonCreateDeformableSolid(world, tetrahedra, materialID);

		//create a rigid body with a deformable mesh
		m_body = CreateRigidBody (scene, mass, deformableCollision);

		// create the soft body mesh
		DemoMesh* const mesh = new TetrahedraSoftMesh(scene, tetrahedra, m_body);
		SetMesh(mesh, dGetIdentityMatrix());

		// do not forget to destroy this objects, else you get bad memory leaks.
		mesh->Release ();
		NewtonMeshDestroy (tetrahedra);
		NewtonDestroyCollision(deformableCollision);
	}
	PlaformEntityEntity (DemoEntityManager* const scene, DemoEntity* const source, NewtonBody* const triggerPort0, NewtonBody* const triggerPort1)
		:DemoEntity (source->GetNextMatrix(), NULL)
	{
		scene->Append(this);

		DemoMesh* const mesh = (DemoMesh*)source->GetMesh();
		dAssert (mesh->IsType(DemoMesh::GetRttiType()));

		SetMesh(mesh, source->GetMeshMatrix());

		const dFloat mass = 100.0f;
		dMatrix matrix (source->GetNextMatrix()) ;
		NewtonWorld* const world = scene->GetNewton();

		// note: because the mesh matrix can have scale, for simplicity just apply the local mesh matrix to the vertex cloud
		dVector pool[128];
		const dMatrix& meshMatrix = GetMeshMatrix();
		meshMatrix.TransformTriplex(&pool[0].m_x, sizeof (dVector), mesh->m_vertex, 3 * sizeof (dFloat), mesh->m_vertexCount);
		NewtonCollision* const collision = NewtonCreateConvexHull(world, mesh->m_vertexCount, &pool[0].m_x, sizeof (dVector), 0, 0, NULL);

		NewtonBody* body = CreateSimpleBody (world, this, 100, matrix, collision, 0);
		NewtonDestroyCollision(collision);


		// attach a kinematic joint controller joint to move this body 
		dVector pivot;
		NewtonBodyGetCentreOfMass (body, &pivot[0]);
		pivot = matrix.TransformVector(pivot);
		m_driver = new FerryDriver (body, pivot, triggerPort0, triggerPort1);
		m_driver->SetMaxLinearFriction (50.0f * dAbs (mass * DEMO_GRAVITY)); 
		m_driver->SetMaxAngularFriction(50.0f * dAbs (mass * DEMO_GRAVITY)); 
	}
Exemple #7
0
CCruiser::CCruiser(std::vector<CPlayer*>* players, BulletList* playerBullets, BulletList* enemyBullets) : CEnemy(players, playerBullets, enemyBullets)
{
	SetMesh(HAVOC_BOSS_MESH);

	//Ensure model is reset in the case it reuses a cached model
	mModel->ResetScale();
	mModel->ResetOrientation();

	mModel->RotateY(180.0f);

	mWeapon.reset(new CMissileBarrage(this, 10, 75.0f, 0.1f));
	mWeapon->SetBulletList(enemyBullets);
	mWeapon->SetEnemyBulletList(playerBullets);
	mWeapon->SetFiring(false);

	/*if (static_cast<int>(players->size()) > 0)
	{
		mWeapon->SetTarget((*players)[0]);
	}*/

	SetHealth(25);
	SetRadius(kRadius);
	SetValue(50);
	SetSpeed(30.0f);
	mStateTimer = 0.0f;
	mState = State::Enter;
}
Exemple #8
0
//Nick Cage Mode
void CCruiser::ActivateTheCage()
{
	SetMesh(PARTICLE_MODEL, NICK_CAGE);
	mModel->ResetScale();
	mModel->Scale(kRadius);
	mWeapon->ActivateTheCage();
}
Exemple #9
0
MeshObject::MeshObject(CTSTR lpMeshResource)
{
    traceIn(MeshObject::MeshObject);

    SetMesh(lpMeshResource);

    traceOut;
}
void SecurityCamera::Update(double dt, TileMap* _map)
{
	if (!m_state)
	{
		m_timer -= dt;
		if (m_timer <= 0.f) // Activate camera and reset timer for next use
		{
			m_state = true;
			if (m_dir == Direction::DIRECTIONS[Direction::DIR_UP])
			{
				SetMesh(s_camMeshList[CAM_ON_UP]);
				// Force set tilemap
				Tile* _tile = _map->GetTileAt(GetMapPos());
				_tile->SetMesh(s_camMeshList[CAM_ON_UP]);
				_tile->SetType(Tile::TILE_OBJ_CAMERA_ON_1_3);
			}
			else if (m_dir == Direction::DIRECTIONS[Direction::DIR_DOWN])
			{
				SetMesh(s_camMeshList[CAM_ON_DOWN]);
				// Force set tilemap
				Tile* _tile = _map->GetTileAt(GetMapPos());
				_tile->SetMesh(s_camMeshList[CAM_ON_DOWN]);
				_tile->SetType(Tile::TILE_OBJ_CAMERA_ON_1_1);
			}
			else if (m_dir == Direction::DIRECTIONS[Direction::DIR_LEFT])
			{
				SetMesh(s_camMeshList[CAM_ON_LEFT]);
				// Force set tilemap
				Tile* _tile = _map->GetTileAt(GetMapPos());
				_tile->SetMesh(s_camMeshList[CAM_ON_LEFT]);
				_tile->SetType(Tile::TILE_OBJ_CAMERA_ON_1_2);
			}
			else if (m_dir == Direction::DIRECTIONS[Direction::DIR_RIGHT])
			{
				SetMesh(s_camMeshList[CAM_ON_RIGHT]);
				// Force set tilemap
				Tile* _tile = _map->GetTileAt(GetMapPos());
				_tile->SetMesh(s_camMeshList[CAM_ON_RIGHT]);
				_tile->SetType(Tile::TILE_OBJ_CAMERA_ON_1_4);
			}
			GenerateViewBox(_map);
			m_timer = S_M_CAMERA_MAX_TIMER;
		}
	}
}
Exemple #11
0
Tower::Tower(Game & game) : Actor (game){
	//Get Asset Cache
	auto& assetCache = game.GetAssetCache();

	//Create a mesh component
	auto meshComponent = MeshComponent::Create(*this);
	auto mesh = assetCache.Load<Mesh>("Meshes/TowerBase.itpmesh2");
	meshComponent->SetMesh(mesh);
}
Exemple #12
0
Graphics::Graphics(egl::graphics::ShaderRef shader, egl::graphics::ShaderRef light_shader, egl::Camera* camera) 
	: renderer_(shader, light_shader, *camera) {
	auto mesh = egl::graphics::MakeTestMesh(shader->GetAttributeMap());
	auto simple_gl_drawable = std::make_unique<SimpleGLObject>("data/test3.png");	
	simple_gl_drawable->SetMesh(mesh);

	draw_types_.push_back(std::move(simple_gl_drawable));
	draw_types_.push_back(std::make_unique<temp::LightMesh>(light_shader->GetAttributeMap(), 0.025f));
}
Exemple #13
0
CubeRobot::CubeRobot(void)	{	
	if(!cube) {
		CreateCube();
	}
	SetMesh(cube);

	//Make the body
	SceneNode*body = new SceneNode(cube,Vector4(1,0,0,1));
	body->SetModelScale(Vector3(10,15,5));
	body->SetTransform(Matrix4::Translation(Vector3(0,35,0)));
	AddChild(body);

	//Add the head
	head = new SceneNode(cube,Vector4(0,1,0,1));
	head->SetModelScale(Vector3(5,5,5));
	head->SetTransform(Matrix4::Translation(Vector3(0,30,0)));
	body->AddChild(head);

	//Add the left arm
	leftArm = new SceneNode(cube,Vector4(0,0,1,1));
	leftArm->SetModelScale(Vector3(3,-18,3));
	leftArm->SetTransform(Matrix4::Translation(Vector3(-12,30,-1)));
	body->AddChild(leftArm);

	//Add the right arm
	rightArm = new SceneNode(cube,Vector4(0,0,1,1));
	rightArm->SetModelScale(Vector3(3,-18,3));
	rightArm->SetTransform(Matrix4::Translation(Vector3(12,30,-1)));
	body->AddChild(rightArm);

	//Add the left leg
	leftLeg = new SceneNode(cube,Vector4(0,0,1,1));
	leftLeg->SetModelScale(Vector3(3,-17.5,3));
	leftLeg->SetTransform(Matrix4::Translation(Vector3(-8,0,0)));
	body->AddChild(leftLeg);

	//Finally the right leg!
	rightLeg = new SceneNode(cube,Vector4(0,0,1,1));
	rightLeg->SetModelScale(Vector3(3,-17.5,3));
	rightLeg->SetTransform(Matrix4::Translation(Vector3(8,0,0)));
	body->AddChild(rightLeg);

	//Giant CubeRobot!
	//transform = Matrix4::Scale(Vector3(10,10,10));

	//The Scene Management Tutorial introduces these, as cheap culling tests
	body->SetBoundingRadius(15.0f);
	head->SetBoundingRadius(5.0f);

	leftArm->SetBoundingRadius(18.0f);
	rightArm->SetBoundingRadius(18.0f);

	leftLeg->SetBoundingRadius(18.0f);
	rightLeg->SetBoundingRadius(18.0f);
}
Exemple #14
0
// The spawner object class constructor.
SpawnerObject::SpawnerObject( char *name, char *path, unsigned long type ) : SceneObject( type )
{
	// Set spawner objects as ghosts.
	SetGhost( true );

	// Load the spawner's script.
	Script *script = new Script( name, path );

	// Get the spawner's frequency.
	m_frequency = *script->GetFloatData( "frequency" );
	
	// Clear the spawn timer.
	m_spawnTimer = 0.0f;

	// Load the sound to play when the spawner's object is collected.
	if( script->GetStringData( "sound" ) != NULL )
	{
		m_sound = new Sound( script->GetStringData( "sound" ) );
		m_audioPath = new AudioPath3D;
	}

	// No object found, so clear pointers for sound and audio
	else
	{
		m_sound = NULL;
		m_audioPath = NULL;
	}

	// Load the script for the spawner's object.
	m_objectScript = g_engine->GetScriptManager()->Add( script->GetStringData( "object" ), script->GetStringData( "object_path" ) );

	// Get the name of the spawner's object.
	m_name = new char[strlen( m_objectScript->GetStringData( "name" ) ) + 1];
	strcpy( m_name, m_objectScript->GetStringData( "name" ) );

	// Set the spawner's mesh to use the object's mesh.
	SetMesh( m_objectScript->GetStringData( "mesh" ), m_objectScript->GetStringData( "mesh_path" ) );

	// Set the object to spin slowly.
	SetSpin( 0.0f, 1.0f, 0.0f );

	// Get the spawner's radius. A radius of 0.0 indicates that it must be
	// taken from the object to be spawned.
	if( *script->GetFloatData( "radius" ) != 0.0f )
		SetBoundingSphere( D3DXVECTOR3( 0.0f, 0.0f, 0.0f ), *script->GetFloatData( "radius" ) );

	// Get mesh for spawner's ellipse radius
	else if( GetMesh() != NULL )
		SetEllipsoidRadius( *m_objectScript->GetVectorData( "ellipse_radius" ) );

	// Destroy the spawner's script.
	SAFE_DELETE( script );

}
	Painting::Painting(ID3D11Device* device, ID3D11DeviceContext* context)
		: MeshInstance(device), texture(0), width(5.0), height(5.0)
	{
		InitTexture(context);
		TestMaterial* canvasMaterial = new TestMaterial(device);
		SetMesh(new PlaneMesh(device, width, height));
		SetMaterial(canvasMaterial);
		canvasMaterial->Init();
		SetActiveTechniqueByName("TextureTech");		
		canvasMaterial->SetTexture(texture);
	}
Exemple #16
0
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
void M113_Idler::AddVisualizationAssets(VisualizationType vis) {
    ChDoubleIdler::AddVisualizationAssets(vis);

    if (vis == VisualizationType::MESH) {
        geometry::ChTriangleMeshConnected trimesh;
        trimesh.LoadWavefrontMesh(GetMeshFile(), false, false);
        auto trimesh_shape = std::make_shared<ChTriangleMeshShape>();
        trimesh_shape->SetMesh(trimesh);
        trimesh_shape->SetName(GetMeshName());
        m_wheel->AddAsset(trimesh_shape);
    }
}
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
void SingleRoadWheel::AddVisualizationAssets(VisualizationType vis) {
    if (vis == VisualizationType::MESH && m_has_mesh) {
        geometry::ChTriangleMeshConnected trimesh;
        trimesh.LoadWavefrontMesh(vehicle::GetDataFile(m_meshFile), false, false);
        auto trimesh_shape = std::make_shared<ChTriangleMeshShape>();
        trimesh_shape->SetMesh(trimesh);
        trimesh_shape->SetName(m_meshName);
        m_wheel->AddAsset(trimesh_shape);
    } else {
        ChSingleRoadWheel::AddVisualizationAssets(vis);
    }
}
Exemple #18
0
void FntLabel::UpdateMesh()
{
	if (mString.IsEmpty())
	{
		if (mFont->HasSinglePage() && mFont->IsFixed())
		{
			SetMesh(nullptr);
			SetMaterial(nullptr);
		}

		if (!mManagedNodes.IsEmpty())
		{
			DeleteAllChilds(NodeRemoveFlags::OnlyManaged);
		}
		SetSize(Size2F::Zero);
		mInternalMeshes.Clear();
		return;
	}
	else if (mRenderingObject.Mesh() ==nullptr)
	{
		CreateMesh();
	}


	Size2F outSize;

	if (mIsMultipleLine)
	{
		TextLayouter::LayoutMultipleLineText(mInternalMeshes, mInternalPages, outSize, *mFont, mString, mAlignment, mRestrictSize, this, mIsStatic);
	}
	else
	{
		TextLayouter::LayoutSingleLineText(mInternalMeshes, mInternalPages, outSize, *mFont, mString, mAlignment, mRestrictSize, this, mIsStatic);
	}

	SetSize(outSize);

	//check if there are some mesh has no char after layout,this is rarely hit
	size_t meshCount = mInternalMeshes.Count();
	if (meshCount>1)
	{
		List<size_t> unusedIndices;
		List<INode*> unusedSprites;
		FOR_EACH_SIZE(i, meshCount)
		{
			BaseFontMesh* mesh = mInternalMeshes[i];
			if (!mesh->HasChars())
			{
				unusedIndices.Add(i);
				unusedSprites.Add(mManagedNodes[i]);
			}
		}
Exemple #19
0
    std::map<unsigned int, SceneNode *> SceneManager::CreateNodes(const std::map<unsigned int, std::shared_ptr<EntityComponent> > components, SceneNode * pParent)
    {
        std::map<unsigned int, SceneNode *> nodes;

        for (auto component : components)
        {
            // creat this node
            std::shared_ptr<SceneComponent> scene_component = std::dynamic_pointer_cast<SceneComponent>(component.second);
            auto node = new SceneNode(pParent, scene_component);

            // add any necessary assets to the scene node
            // XXX this should also happen during update incase the model asset is changed anytime during 
            // the scene components life cycle
            if (auto mesh_component = std::dynamic_pointer_cast<MeshComponent>(scene_component))
            {
                auto path = mesh_component->GetMeshPath();
                if (m_pAssets != nullptr)
                {
                    auto asset = m_pAssets->GetAsset(path.c_str());
                    node->SetMesh(asset);
                }
            }

            // get the material path, load as an asset, and set it on the node.
            auto material_path = scene_component->GetMaterialPath();
            std::shared_ptr<Material> pMaterial;
            if (m_pAssets != nullptr)
            {
                auto pAsset = m_pAssets->GetAsset(material_path.c_str());

                // XXX TODO - pass asset through a material manager, so that only one
                // material every exists for a given material script.
                pMaterial = std::make_shared<Material>(pAsset);
                node->SetMaterial(pMaterial);
            }

            if (auto light_component = std::dynamic_pointer_cast<LightComponent>(scene_component))
            {
                // create a light based on the light component and set it on the scene node
                Light * pLight = new Light(light_component);
                node->SetLight(pLight);
            }

            // do a depth first creation, so the list of child nodes can be passed into the scene node creation.
            std::map<unsigned int, SceneNode *> child_nodes = this->CreateNodes(component.second->GetComponents(), node);
            node->SetChildren(child_nodes);

            nodes[component.first] = node;
        }

        return nodes;
    }
Exemple #20
0
Asteroid::Asteroid(Game& game) : Super(game)
{
    auto mesh = MeshComponent::Create(*this);
    auto meshPtr = game.GetAssetCache().Load<Mesh>("Meshes/AsteroidMesh.itpmesh2");
    mesh->SetMesh(meshPtr);
    
    auto movement = MoveComponent::Create(*this, Component::PreTick);
    movement->SetLinearSpeed(150.0f);
    movement->SetLinearAxis(1.0f);
    
    SetRotation(Random::GetRotation());
	SetScale( 0.1f );
}
FrostTower::FrostTower(Game & game) : Tower(game){
	//Get Asset Cache
	auto& assetCache = game.GetAssetCache();

	//Create a mesh component
	auto meshComponent = MeshComponent::Create(*this);
	auto mesh = assetCache.Load<Mesh>("Meshes/Frost.itpmesh2");
	meshComponent->SetMesh(mesh);

	//Set Frost timer
	TimerHandle handle;
	mGame.GetTime().SetTimer(handle, this, &FrostTower::FrostEnemies, 2.0f, true);
}
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
void TrackShoeBandBushing::AddVisualizationAssets(VisualizationType vis) {
    if (vis == VisualizationType::MESH && m_has_mesh) {
        auto trimesh = std::make_shared<geometry::ChTriangleMeshConnected>();
        trimesh->LoadWavefrontMesh(vehicle::GetDataFile(m_meshFile), false, false);
        auto trimesh_shape = std::make_shared<ChTriangleMeshShape>();
        trimesh_shape->SetMesh(trimesh);
        trimesh_shape->SetName(m_meshName);
        trimesh_shape->SetStatic(true);
        m_shoe->AddAsset(trimesh_shape);
    } else {
        ChTrackShoeBandBushing::AddVisualizationAssets(vis);
    }
}
DemoEntity::DemoEntity(DemoEntityManager& world, const dScene* scene, dScene::dTreeNode* rootSceneNode, dTree<DemoMesh*, dScene::dTreeNode*>& 	 	meshCache, DemoEntityManager::EntityDictionary& entityDictionary, DemoEntity* parent)
	:dClassInfo()
	,dHierarchy<DemoEntity>() 
	,m_matrix(GetIdentityMatrix()) 
	,m_curPosition (0.0f, 0.0f, 0.0f, 1.0f)
	,m_nextPosition (0.0f, 0.0f, 0.0f, 1.0f)
	,m_curRotation (1.0f, 0.0f, 0.0f, 0.0f)
	,m_nextRotation (1.0f, 0.0f, 0.0f, 0.0f)
	,m_lock (0)
	,m_mesh (NULL)
{
	// add this entity to the dictionary
	entityDictionary.Insert(this, rootSceneNode);

	// if this is a child mesh set it as child of th entity
	dMatrix parentMatrix (GetIdentityMatrix());
	if (parent) {
		Attach (parent);

		dScene::dTreeNode* parentNode = scene->FindParentByType(rootSceneNode, dSceneNodeInfo::GetRttiType());
		dSceneNodeInfo* parentInfo = (dSceneNodeInfo*) parentNode;
		parentMatrix = parentInfo->GetTransform();
	}

	dSceneNodeInfo* info = (dSceneNodeInfo*) scene->GetInfoFromNode (rootSceneNode);
//	SetMatrix(info->GetTransform() * parentMatrix.Inverse4x4());
	dMatrix matrix (info->GetTransform() * parentMatrix.Inverse4x4());
	dQuaternion rot (matrix);

	// set the matrix twice in oder to get cur and next position
	SetMatrix(world, rot, matrix.m_posit);
	SetMatrix(world, rot, matrix.m_posit);


	// if this node has a mesh, find it and attach it to this entity
	dScene::dTreeNode* meshNode = scene->FindChildByType(rootSceneNode, dMeshNodeInfo::GetRttiType());
	if (meshNode) {
		DemoMesh* mesh = meshCache.Find(meshNode)->GetInfo();
		SetMesh(mesh);
	}

	// add all of the children nodes as child nodes
	for (void* child = scene->GetFirstChild(rootSceneNode); child; child = scene->GetNextChild (rootSceneNode, child)) {
		dScene::dTreeNode* node = scene->GetNodeFromLink(child);
		dNodeInfo* info = scene->GetInfoFromNode(node);
		if (info->GetTypeId() == dSceneNodeInfo::GetRttiType()) {
			new DemoEntity (world, scene, node, meshCache, entityDictionary, this);
		}
	}
}
Exemple #24
0
Asteroid::Asteroid(Game& game)
:Actor(game)
{
    // Face in a random direction
    //SetRotation(Random::GetFloatRange(0.0f, Math::TwoPi));
    
    auto mesh = mGame.GetAssetCache().Load<Mesh>("Meshes/AsteroidMesh.itpmesh2");
    auto meshC = MeshComponent::Create(*this);
    meshC->SetMesh(mesh);
        
    auto coll = SphereCollision::Create(*this);
    coll->RadiusFromMesh(mesh);
    coll->SetScale(0.1f);
}
		ClosestDistanceEntity (DemoEntityManager* const scene, dMatrix& matrix, int materialID, PrimitiveType castingShapeType)
			:DemoEntity (matrix, NULL)
			,m_contactsCount(0)
		{
			NewtonWorld* const world = scene->GetNewton();

			dVector size(1.0f, 1.0f, 1.0f, 0.0f);
			m_castingShape = CreateConvexCollision (world, dGetIdentityMatrix(), size, castingShapeType, 0);

			DemoMesh* const geometry = new DemoMesh("convexShape", m_castingShape, "smilli.tga", "smilli.tga", "smilli.tga");
			SetMesh(geometry, dGetIdentityMatrix());
			geometry->Release();

			scene->Append(this);
		}
	BasicPlayerEntity (DemoEntityManager* const scene, CustomPlayerControllerManager* const manager, dFloat radius, dFloat height, const dMatrix& location)
		:DemoEntity (dGetIdentityMatrix(), NULL)
	{
		// add this entity to the scene for rendering
		scene->Append(this);

		// now make a simple player controller, 
		dMatrix playerAxis; 
		playerAxis[0] = dVector (0.0f, 1.0f, 0.0f, 0.0f); // the y axis is the character up vector
		playerAxis[1] = dVector (1.0f, 0.0f, 0.0f, 0.0f); // the x axis is the character front direction
		playerAxis[2] = playerAxis[0].CrossProduct(playerAxis[1]);
		playerAxis[3] = dVector (0.0f, 0.0f, 0.0f, 1.0f);

		// make the player controller, this function makes a kinematic body
		m_controller = manager->CreatePlayer(PLAYER_MASS, radius, radius * 0.5f, height, height * 0.33f, playerAxis);
		//m_controller = manager->CreatePlayer(200.0f, 0.5f, 0.4f, 2.0f, 0.5f, playerAxis);

		// players by default have the origin at the center of mass of the collision shape.
		// you can change this by calling SetPlayerOrigin, for example if a player has its origin at the lower bottom of its AABB 
		m_controller->SetPlayerOrigin(height * 0.0f);

		// set a restraining distance that the player can not get closet than
		m_controller->SetRestrainingDistance(0.1f);


		// players by default have the origin at the center of the lower bottom of the collision shape.
		// you can change this by calling SetPlayerOrigin, for example if a player has it origin at the center of the AABB you can call 
		//m_controller->SetPlayerOrigin (height * 0.5f);

		// get body from player, and set some parameter
		NewtonBody* const body = m_controller->GetBody();

		// set the user data
		NewtonBodySetUserData(body, this);

		// set the transform callback
		NewtonBodySetTransformCallback (body, DemoEntity::TransformCallback);

		// set the player matrix 
		NewtonBodySetMatrix(body, &location[0][0]);

		// create the visual mesh from the player collision shape
		NewtonCollision* const collision = NewtonBodyGetCollision(body);
		DemoMesh* const geometry = new DemoMesh("player", collision, "smilli.tga", "smilli.tga", "smilli.tga");
		SetMesh(geometry, dGetIdentityMatrix());
		geometry->Release(); 
	}
Asteroid::Asteroid(Game& game) : Actor(game)
{
    auto meshComponent = MeshComponent::Create(*this);
    auto mesh = game.GetAssetCache().Load<Mesh>("Meshes/AsteroidMesh.itpmesh2");
    auto texture = game.GetAssetCache().Load<Texture>("Textures/Asteroid.png");
    meshComponent->SetMesh(mesh);
    
    SetRotation(Random::GetFloatRange(0.0f, Math::TwoPi));
    
    auto move = MoveComponent::Create(*this, Component::PreTick);
    move -> SetLinearSpeed(150.0f);
    move -> SetLinearAxis(1.0f);
    
    auto col = SphereCollision::Create(*this);
    col->SetScale(0.9f);
    col->RadiusFromTexture(texture);
}
Exemple #28
0
void WBCompEldMesh::Load(const IDataStream& Stream) {
  XTRACE_FUNCTION;

  ASSERT(m_Mesh);

  const uint Version = Stream.ReadUInt32();

  if (Version >= VERSION_MESHNAME) {
    const SimpleString MeshName = Stream.ReadString();
    if (MeshName != m_MeshName) {
      SetMesh(MeshName);
    }
  }

  if (Version >= VERSION_TEXTURENAME) {
    const SimpleString TextureName = Stream.ReadString();
    if (TextureName != m_TextureName) {
      SetTexture(TextureName);
    }
  }

  if (Version >= VERSION_MESHSCALE) {
    Stream.Read(sizeof(Vector), &m_Mesh->m_Scale);
  }

  if (Version >= VERSION_HIDDEN) {
    m_Hidden = Stream.ReadBool();
  }

  if (Version >= VERSION_ANIMATION) {
    const int AnimationIndex = Stream.ReadInt32();
    const float AnimationTime = Stream.ReadFloat();
    const int AnimationEndBehavior = Stream.ReadInt32();
    const float AnimationPlayRate =
        (Version >= VERSION_ANIMRATE) ? Stream.ReadFloat() : 1.0f;

    if (m_Mesh->IsAnimated()) {
      WB_MAKE_EVENT(SetAnim, GetEntity());
      WB_SET_AUTO(SetAnim, Int, AnimationIndex, AnimationIndex);
      WB_SET_AUTO(SetAnim, Float, AnimationTime, AnimationTime);
      WB_SET_AUTO(SetAnim, Int, AnimationEndBehavior, AnimationEndBehavior);
      WB_SET_AUTO(SetAnim, Float, AnimationPlayRate, AnimationPlayRate);
      WB_QUEUE_EVENT(GetEventManager(), SetAnim, GetEntity());
    }
  }
}
void Skybox::Initialise(ID3D11Device *device, HWND hwnd)
{
	GameObject::Initialise(device, hwnd);

	Mesh* skyMesh = new Mesh;
	ID3D11DeviceContext* context;
	device->GetImmediateContext(&context);
	skyMesh->Initialise(device, context, "skydome.txt", "../WaveSim/Data/Textures/skybox.tga");
	SetMesh(skyMesh);

	//Initialise ambient light
	m_skyBoxAmbientLight = new Light;
	m_skyBoxAmbientLight->SetDiffuseColour(1.0f, 1.0f, 1.0f, 1.0f);
	m_skyBoxAmbientLight->SetSpecularColour(0.0f, 0.0f, 0.0f, 0.0f);
	m_skyBoxAmbientLight->SetSpecularPower(10000.0f);
	m_skyBoxAmbientLight->SetAmbientColour(1.0f, 1.0f, 1.0f, 1.0f);
	m_skyBoxAmbientLight->SetDirection(0, -1, 1);
}
void MeshComponent::SetProperties(const rapidjson::Value& properties)
{
	Super::SetProperties(properties);

	int textureIndex;
	std::string meshName;

	if(GetStringFromJSON(properties, "mesh", meshName))
	{
		auto mesh = mOwner.GetGame().GetAssetCache().Load<Mesh>(meshName);

		SetMesh(mesh);

		if(GetIntFromJSON(properties, "textureIndex", textureIndex))
		{
			SetTextureIndex(textureIndex);
		}
	}
}