A full translation of most of http://www.ogre3d.org/tikiwiki/Basic+Tutorial+1&structure=Tutorials.


import dogre.all;
import std.stdio;

pragma(lib, "Dogre.lib");

void main()
{
    Root r = new Root();

    if(!(r.restoreConfig || r.showConfigDialog))
        return;

    r.saveConfig();
    
    ConfigFile cf = new ConfigFile;
    cf.load("resources_d.cfg");
    ConfigFile.SectionIterator seci = cf.getSectionIterator();
    
    string secname;

    while(seci.hasMoreElements())
    {
        secname = seci.peekNextKey();
        auto settings = seci.getNext();
        
        foreach(string typename, string archname; settings)
        {
            ResourceGroupManager.getSingleton().addResourceLocation(archname, typename,secname); 
        }
    }

    
    
    SceneManager sm = r.createSceneManager(ST_GENERIC);
    RenderWindow win = r.initialise(true, "My Window");
    Camera mycam = sm.createCamera("PlayerCam");
    Vector3 vec = new Vector3(0,0,80);
    mycam.setPosition(vec);
    mycam.lookAt(new Vector3(0,0,-300));
    mycam.setNearClipDistance(5);
    
    Viewport vp = win.addViewport(mycam);
    vp.setBackgroundColour(new ColourValue(0,0,0));
    mycam.setAspectRatio(cast(float)vp.getActualWidth() / cast(float)vp.getActualHeight());
    
    ResourceGroupManager.getSingleton().initialiseAllResourceGroups();
    Entity ogreHead;
    try
    {
        ogreHead = sm.createEntity("Head", "ogrehead.mesh");
    }
    catch(OgreException e)
    {
        writeln(e.msg);
        throw e;
    }
    
    
    SceneNode sn = sm.getRootSceneNode();
    SceneNode headNode = sn.createChildSceneNode();
    
    headNode.attachObject(ogreHead);
    sm.setAmbientLight(new ColourValue(0.5, 0.5, 0.5));
    Light l = sm.createLight("MainLight");
    l.setPosition(20, 80, 50);
    
    while(true)
    {
        WindowEventUtilities.messagePump();
        if(win.isClosed())
        {
            break;
        }
        
        if(!r.renderOneFrame()) break;
    }
    
    clear(r);
}


ogrehead_works.png

Last edited Nov 15, 2010 at 12:27 AM by jcao219, version 5

Comments

No comments yet.