Similar topics
User Yang Sedang Online
Total 1 user online :: 0 Terdaftar, 0 Tersembunyi dan 1 Tamu Tidak ada
User online terbanyak adalah 34 pada Tue Oct 22, 2024 10:15 pm
Archieve
Code Static Geometry
2 posters
:: Sumber Informasi :: Ogre
Halaman 1 dari 1
Code Static Geometry
#include "ExampleApplication.h"
class TutorialApplication : public ExampleApplication
{
protected:
public:
TutorialApplication()
{
}
~TutorialApplication()
{
}
protected:
MeshPtr mGrassMesh;
void createGrassMesh()
{
const float width = 25;
const float height = 30;
ManualObject mo("GrassObject");
Vector3 vec(width/2, 0, 0);
Quaternion rot;
rot.FromAngleAxis(Degree(60), Vector3::UNIT_Y);
mo.begin("Examples/GrassBlades", RenderOperation::OT_TRIANGLE_LIST);
for (int i = 0; i < 3; ++i)
{
mo.position(-vec.x, height, -vec.z);
mo.textureCoord(0, 0);
mo.position(vec.x, height, vec.z);
mo.textureCoord(1, 0);
mo.position(-vec.x, 0, -vec.z);
mo.textureCoord(0, 1);
mo.position(vec.x, 0, vec.z);
mo.textureCoord(1, 1);
int offset = i * 4;
mo.triangle(offset, offset+3, offset+1);
mo.triangle(offset, offset+2, offset+3);
vec = rot * vec;
}
mo.end();
mo.convertToMesh("GrassBladesMesh");
}
void createScene(void)
{
createGrassMesh();
mSceneMgr->setAmbientLight(ColourValue(1, 1, 1));
mCamera->setPosition(150, 50, 150);
mCamera->lookAt(0, 0, 0);
Entity *robot = mSceneMgr->createEntity("robot", "robot.mesh");
mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(robot);
Plane plane;
plane.normal = Vector3::UNIT_Y;
plane.d = 0;
MeshManager::getSingleton().createPlane("floor",
ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, plane,
450,450,10,10,true,1,50,50,Vector3::UNIT_Z);
Entity* pPlaneEnt = mSceneMgr->createEntity("plane", "floor");
pPlaneEnt->setMaterialName("Examples/GrassFloor");
pPlaneEnt->setCastShadows(false);
mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(pPlaneEnt);
Entity *grass = mSceneMgr->createEntity("grass", "GrassBladesMesh");
StaticGeometry *sg = mSceneMgr->createStaticGeometry("GrassArea");
const int size = 375;
const int amount = 20;
sg->setRegionDimensions(Vector3(size, size, size));
sg->setOrigin(Vector3(-size/2, 0, -size/2));
for (int x = -size/2; x < size/2; x += (size/amount))
for (int z = -size/2; z < size/2; z += (size/amount))
{
Real r = size / (float)amount / 2;
Vector3 pos(x + Math::RangeRandom(-r, r), 0, z + Math::RangeRandom(-r, r));
Vector3 scale(1, Math::RangeRandom(0.9, 1.1), 1);
Quaternion orientation;
orientation.FromAngleAxis(Degree(Math::RangeRandom(0, 359)), Vector3::UNIT_Y);
sg->addEntity(grass, pos, orientation, scale);
}
sg->build();
}
};
#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
#define WIN32_LEAN_AND_MEAN
#include "windows.h"
INT WINAPI WinMain(HINSTANCE hInst, HINSTANCE, LPSTR strCmdLine, INT)
#else
int main(int argc, char **argv)
#endif
{
// Create application object
TutorialApplication app;
try {
app.go();
} catch(Exception& e) {
#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
MessageBoxA(NULL, e.getFullDescription().c_str(), "An exception has occurred!", MB_OK | MB_ICONERROR | MB_TASKMODAL);
#else
fprintf(stderr, "An exception has occurred: %s\\n",
e.getFullDescription().c_str());
#endif
}
return 0;
}
class TutorialApplication : public ExampleApplication
{
protected:
public:
TutorialApplication()
{
}
~TutorialApplication()
{
}
protected:
MeshPtr mGrassMesh;
void createGrassMesh()
{
const float width = 25;
const float height = 30;
ManualObject mo("GrassObject");
Vector3 vec(width/2, 0, 0);
Quaternion rot;
rot.FromAngleAxis(Degree(60), Vector3::UNIT_Y);
mo.begin("Examples/GrassBlades", RenderOperation::OT_TRIANGLE_LIST);
for (int i = 0; i < 3; ++i)
{
mo.position(-vec.x, height, -vec.z);
mo.textureCoord(0, 0);
mo.position(vec.x, height, vec.z);
mo.textureCoord(1, 0);
mo.position(-vec.x, 0, -vec.z);
mo.textureCoord(0, 1);
mo.position(vec.x, 0, vec.z);
mo.textureCoord(1, 1);
int offset = i * 4;
mo.triangle(offset, offset+3, offset+1);
mo.triangle(offset, offset+2, offset+3);
vec = rot * vec;
}
mo.end();
mo.convertToMesh("GrassBladesMesh");
}
void createScene(void)
{
createGrassMesh();
mSceneMgr->setAmbientLight(ColourValue(1, 1, 1));
mCamera->setPosition(150, 50, 150);
mCamera->lookAt(0, 0, 0);
Entity *robot = mSceneMgr->createEntity("robot", "robot.mesh");
mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(robot);
Plane plane;
plane.normal = Vector3::UNIT_Y;
plane.d = 0;
MeshManager::getSingleton().createPlane("floor",
ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, plane,
450,450,10,10,true,1,50,50,Vector3::UNIT_Z);
Entity* pPlaneEnt = mSceneMgr->createEntity("plane", "floor");
pPlaneEnt->setMaterialName("Examples/GrassFloor");
pPlaneEnt->setCastShadows(false);
mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(pPlaneEnt);
Entity *grass = mSceneMgr->createEntity("grass", "GrassBladesMesh");
StaticGeometry *sg = mSceneMgr->createStaticGeometry("GrassArea");
const int size = 375;
const int amount = 20;
sg->setRegionDimensions(Vector3(size, size, size));
sg->setOrigin(Vector3(-size/2, 0, -size/2));
for (int x = -size/2; x < size/2; x += (size/amount))
for (int z = -size/2; z < size/2; z += (size/amount))
{
Real r = size / (float)amount / 2;
Vector3 pos(x + Math::RangeRandom(-r, r), 0, z + Math::RangeRandom(-r, r));
Vector3 scale(1, Math::RangeRandom(0.9, 1.1), 1);
Quaternion orientation;
orientation.FromAngleAxis(Degree(Math::RangeRandom(0, 359)), Vector3::UNIT_Y);
sg->addEntity(grass, pos, orientation, scale);
}
sg->build();
}
};
#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
#define WIN32_LEAN_AND_MEAN
#include "windows.h"
INT WINAPI WinMain(HINSTANCE hInst, HINSTANCE, LPSTR strCmdLine, INT)
#else
int main(int argc, char **argv)
#endif
{
// Create application object
TutorialApplication app;
try {
app.go();
} catch(Exception& e) {
#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
MessageBoxA(NULL, e.getFullDescription().c_str(), "An exception has occurred!", MB_OK | MB_ICONERROR | MB_TASKMODAL);
#else
fprintf(stderr, "An exception has occurred: %s\\n",
e.getFullDescription().c_str());
#endif
}
return 0;
}
Re: Code Static Geometry
gan kalo code geometry yang gerak ada ga gan?
ane mnt donk source code+ langkah - langkahnya donk
ane mnt donk source code+ langkah - langkahnya donk
irfan- Posts : 4
Reputasi : 4
Cendol : 0
Join date : 18.03.11
Re: Code Static Geometry
gan ane juga minta code stimulasi leading ama take off pesawat terbang ada ga gan??
ane bagi donk ...
ane bagi donk ...
irfan- Posts : 4
Reputasi : 4
Cendol : 0
Join date : 18.03.11
Re: Code Static Geometry
1 lagy gan ini w ada tugas grafkom lep
ane ambil judul Animasi Pengenalan Bangun Ruang
ada source code ma langkah - langkahnya ga?
thanks
ane ambil judul Animasi Pengenalan Bangun Ruang
ada source code ma langkah - langkahnya ga?
thanks
irfan- Posts : 4
Reputasi : 4
Cendol : 0
Join date : 18.03.11
:: Sumber Informasi :: Ogre
Halaman 1 dari 1
Permissions in this forum:
Anda tidak dapat menjawab topik