Would you like to react to this message? Create an account in a few clicks or log in to continue.
Chat Box

User Yang Sedang Online
Total 7 uses online :: 0 Terdaftar, 0 Tersembunyi dan 7 Tamu

Tidak ada

[ View the whole list ]


User online terbanyak adalah 24 pada Mon Oct 04, 2010 10:03 am
Total Pengunjung
Website counter
Visitor
Project Grafkom (Objek Bergerak) Labels=0

Project Grafkom (Objek Bergerak)

3 posters

Go down

Project Grafkom (Objek Bergerak) Empty Project Grafkom (Objek Bergerak)

Post by risdo Wed Apr 07, 2010 10:17 am

Teman-teman gw dpt info nie dari forum tetangga ni source code biar bs bergerak



Code:


#include "ExampleApplication.h"

#include
using namespace std;

class MoveDemoListener : public ExampleFrameListener
{
public:

    MoveDemoListener(RenderWindow* win, Camera* cam, SceneNode *sn,
        Entity *ent, deque &walk)
        : ExampleFrameListener(win, cam, false, false), mNode(sn), mEntity(ent), mWalkList(walk)
    {
        // Set default values for variables
        mWalkSpeed = 35.0f;
        mDirection = Vector3::ZERO;
    } // MoveDemoListener

    /* This function is called to start the object moving to the next position
    in mWalkList.
    */
    bool nextLocation()
    {        if (mWalkList.empty())
        return false;
    mDestination = mWalkList.front();  // this gets the front of the deque
    mWalkList.pop_front();            // this removes the front of the deque

    mDirection = mDestination - mNode->getPosition();
    mDistance = mDirection.normalise();

    Vector3 src = mNode->getOrientation() * Vector3::UNIT_X;
    if ((1.0f + src.dotProduct(mDirection)) < 0.0001f)
    {
        mNode->yaw(Degree(180));
    }
    else
    {
        Ogre::Quaternion quat = src.getRotationTo(mDirection);
        mNode->rotate(quat);
    } // else

        return true;
    } // nextLocation()

    bool frameStarted(const FrameEvent &evt)
    {
        if (mDirection == Vector3::ZERO)
        {
            if (nextLocation())
            {
                // Set walking animation
                mAnimationState = mEntity->getAnimationState("Walk");
                mAnimationState->setLoop(true);
                mAnimationState->setEnabled(true);
            }
        }
        else
        {
            Real move = mWalkSpeed * evt.timeSinceLastFrame;
            mDistance -= move;

            if (mDistance <= 0.0f)
            {
                mNode->setPosition(mDestination);
                mDirection = Vector3::ZERO;
                // Set animation based on if the robot has another point to walk to.
                if (! nextLocation())
                {
                    // Set Idle animation
                    mAnimationState = mEntity->getAnimationState("Idle");
                    mAnimationState->setLoop(true);
                    mAnimationState->setEnabled(true);
                }
                else
                {
                    // Rotation Code will go here later
                }
            }
            else
            {
                mNode->translate(mDirection * move);
            } // else
        } // if

       mAnimationState->addTime(evt.timeSinceLastFrame);
        return ExampleFrameListener::frameStarted(evt);
    }
protected:
    Real mDistance;                  // The distance the object has left to travel
    Vector3 mDirection;              // The direction the object is moving
    Vector3 mDestination;            // The destination the object is moving towards

    AnimationState *mAnimationState; // The current animation state of the object

    Entity *mEntity;                // The Entity we are animating
    SceneNode *mNode;                // The SceneNode that the Entity is attached to
    std::deque mWalkList;  // The list of points we are walking to

    Real mWalkSpeed;                // The speed at which the object is moving
};


class MoveDemoApplication : public ExampleApplication
{
protected:
public:
    MoveDemoApplication()
    {
    }

    ~MoveDemoApplication()
    {
    }
protected:
    Entity *mEntity;                // The entity of the object we are animating
    SceneNode *mNode;              // The SceneNode of the object we are moving
    std::deque mWalkList;  // A deque containing the waypoints

    void createScene(void)
    {
       mSceneMgr->setSkyDome(true, "Examples/CloudySky", 5, 8);

        // Set the default lighting.
        mSceneMgr->setAmbientLight(ColourValue(1.0f, 1.0f, 1.0f));
        // Create the entity
        mEntity = mSceneMgr->createEntity("Robot", "robot.mesh");
        // Create the scene node
        mNode = mSceneMgr->getRootSceneNode()->
            createChildSceneNode("RobotNode", Vector3(0.0f, 0.0f, 25.0f));
        mNode->attachObject(mEntity);

        // Create the walking list
        mWalkList.push_back(Vector3(550.0f,  0.0f,  50.0f ));
        mWalkList.push_back(Vector3(-100.0f,  0.0f, -200.0f));
        mWalkList.push_back(Vector3(0.0f, 0.0f, 25.0f));

        // Create objects so we can see movement
        Entity *ent;
        SceneNode *node;

        ent = mSceneMgr->createEntity("Knot1", "knot.mesh");
        node = mSceneMgr->getRootSceneNode()->createChildSceneNode("Knot1Node",
            Vector3(0.0f, -10.0f,  25.0f));
        node->attachObject(ent);
        node->setScale(0.1f, 0.1f, 0.1f);

        ent = mSceneMgr->createEntity("Knot2", "knot.mesh");
        node = mSceneMgr->getRootSceneNode()->createChildSceneNode("Knot2Node",
            Vector3(550.0f, -10.0f,  50.0f));
        node->attachObject(ent);
        node->setScale(0.1f, 0.1f, 0.1f);

        ent = mSceneMgr->createEntity("Knot3", "knot.mesh");
        node = mSceneMgr->getRootSceneNode()->createChildSceneNode("Knot3Node",
            Vector3(-100.0f, -10.0f,-200.0f));
        node->attachObject(ent);
        node->setScale(0.1f, 0.1f, 0.1f);

        /*Plane plane(Vector3::UNIT_Y, 0);
        MeshManager::getSingleton().createPlane("ground",
        ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, plane,
        1500,1500,20,20,true,1,5,5,Vector3::UNIT_Z);

        Entity *ent2 = mSceneMgr->createEntity("GroundEntity", "ground");
        mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(ent2);
        ent2->setMaterialName("Examples/GrassFloor");
        ent2->setCastShadows(false);*/

        // Set the camera to look at our handiwork
        mCamera->setPosition(90.0f, 280.0f, 535.0f);
        mCamera->pitch(Degree(-30.0f));
        mCamera->yaw(Degree(-15.0f));
    }

    void createFrameListener(void)
    {
        mFrameListener= new MoveDemoListener(mWindow, mCamera, mNode, mEntity, mWalkList);
        mFrameListener->showDebugOverlay(true);
        mRoot->addFrameListener(mFrameListener);
    }

};

#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
    MoveDemoApplication app;

    try {
        app.go();
    } catch(Exception& e) {
#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
        MessageBox(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;
}

Cara Penggunaan:
Source File yang dibuat menggunakan nama MoveDemo.cpp
Pada bagian
mSceneMgr->setSkyDome(true, "Examples/CloudySky", 5, Cool;
adalah ..., 5, 8 ); bukan Cool

Saya
akan mencoba jelaskan sedikit tentang coding tersebut. Bagian-bagian
ini bisa dirubah, it's depends with the object. Hal lain yang perlu
diingat adalah animasi dari objek dalam source ini hanya dipanggil/dijalankan.
Untuk membuat animasi pada objek gunakan aplikasi 3d modeling seperti
blender3d, 3ds max, dll. Klo ada salah mohon dimaafkan, namanya juga
belajar... Wink
Berikut adalah sedikit penjelasannya:

Spoiler:

Buat yang mau mengetahui dan belajar langsung tentang logika program ini, bisa melihat link ini
atau mau belajar tentang tutorial ogre lain lihat link ini

Selamat Mencoba & Semoga Berguna



Sumber : http://it-07.forumotion.com/ogre-f8/source-file-animasi-bergerak-t20.htm#44


Terakhir diubah oleh risdo tanggal Wed Apr 07, 2010 1:35 pm, total 3 kali diubah
risdo
risdo
Admin
Admin

Posts : 209
Reputasi : 377
Cendol : 1
Join date : 26.10.09
Location : Bekasi

https://c0b4d1b4c4.indonesianforum.net

Kembali Ke Atas Go down

Project Grafkom (Objek Bergerak) Empty Re: Project Grafkom (Objek Bergerak)

Post by Q_wiLL™ Wed Apr 07, 2010 10:31 am

autis
Q_wiLL™
Q_wiLL™
Admin
Admin

Posts : 138
Reputasi : 208
Cendol : 2
Join date : 27.10.09
Age : 34
Location : dimana kakiku berpijak

http://styaaje.wordpress.com

Kembali Ke Atas Go down

Project Grafkom (Objek Bergerak) Empty Re: Project Grafkom (Objek Bergerak)

Post by risdo Wed Apr 07, 2010 10:42 am

wew ko autis
risdo
risdo
Admin
Admin

Posts : 209
Reputasi : 377
Cendol : 1
Join date : 26.10.09
Location : Bekasi

https://c0b4d1b4c4.indonesianforum.net

Kembali Ke Atas Go down

Project Grafkom (Objek Bergerak) Empty Re: Project Grafkom (Objek Bergerak)

Post by Q_wiLL™ Wed Apr 07, 2010 10:43 am

komen kiting kemana do?
Q_wiLL™
Q_wiLL™
Admin
Admin

Posts : 138
Reputasi : 208
Cendol : 2
Join date : 27.10.09
Age : 34
Location : dimana kakiku berpijak

http://styaaje.wordpress.com

Kembali Ke Atas Go down

Project Grafkom (Objek Bergerak) Empty Re: Project Grafkom (Objek Bergerak)

Post by DJ_and Thu Apr 08, 2010 2:53 pm

beneran .3ds bisa jalan nie disitu.....>> w COba dulu dah
DJ_and
DJ_and

Posts : 61
Reputasi : 95
Cendol : 2
Join date : 28.10.09

Kembali Ke Atas Go down

Project Grafkom (Objek Bergerak) Empty Re: Project Grafkom (Objek Bergerak)

Post by Sponsored content


Sponsored content


Kembali Ke Atas Go down

Kembali Ke Atas

- Similar topics

 
Permissions in this forum:
Anda tidak dapat menjawab topik