Common Knowledge/en

From Ciliz|W4
Revision as of 12:52, 27 May 2020 by Azelenkin (talk | contribs) (Replaced content with "1")

This brief article contains some basic facts about working with the engine.

Installation and Launch Info

1

Test Example

Use the following example:

#include "W4Framework.h"

W4_USE_UNSTRICT_INTERFACE

class W4TemplateGame : public w4::IGame
{
public:
    void onConfig() override
    {
        // todo: configure application behavior
    }
    void onStart() override
    {
        auto cam = render::getScreenCamera();
             cam->setWorldTranslation({0.f, 0, -25.f});
             cam->setFov(45.f);

        m_shape= Mesh::create::cube({5,5,5});
        m_shape->setMaterialInst(Material::getDefault()->createInstance());

        render::getRoot()->addChild(m_shape);

    }
    void onUpdate(float dt) override
    {
        m_shape->rotate(Rotator(dt, dt, dt));
    }
private:
    Mesh::sptr m_shape;
};
W4_RUN(W4TemplateGame)

Expected result: A spinning cube appears.

Interfaces

Interface IGame

virtual void onConfig()         
virtual void onStart()          
virtual void onUpdate(float dt) 
virtual void onExit()           
virtual void onPause()          
virtual void onResume()         
virtual void onLost()           
virtual void onRestore()

Basic Camera Interface

void setFov(float v);
void setAspect(float v);
void setNear(float v);
void setFar(float v);
void setClearColor(const math::vec4& v);
void setClearMask(ClearMask v);

Mesh Generators

 Mesh::create::cube(const math::vec3& size);
 Mesh::create::mappedCube(const math::vec3& size);
 Mesh::create::plane(const math::vec2& size);
 Mesh::create::plane(const math::vec2& xCoords, const math::vec2& yCoords);
 Mesh::create::sphere(float radius, uint32_t rings, uint32_t sectors);
 Mesh::create::cylinder(float height, float radius, uint32_t sectors);
 Mesh::create::capsule(float height, float radius);
 Mesh::create::cone(float radiusTop, float radiusBottom, float height, uint32_t radialSegments, uint32_t heightSegments);
 Mesh::create::diamond(float radiusTop, float radiusBottom, float heightTop, float heightBottom, uint32_t radialSegments, uint32_t heightSegments);
 Mesh::create::torus(float radius, float tube, uint32_t radialSegments, uint32_t tubularSegments, float arc);
 Mesh::create::skybox();

Node Hierarchy Interface

sptr<RootNode> getRoot() const;
sptr getParent() const;
bool hasParent() const;

void addChild(cref, bool preserveTransorm = true);
void addChild(const std::string&, cref, bool preserveTransorm = true);

w4::sptr<T> getChild(const std::string&);
w4::sptr<T> getChild(const std::string&, Args...);

void removeChild(cref);
void removeChild(const std::string&);
void removeChild(const std::list<sptr>&);

std::list<sptr> getAllChildren() const;
std::list<sptr> findChildren(std::string const&) const;
std::list<sptr> findChildrenRecursive(std::string const&) const;

Another Example

Showing various meshes:

#include "W4Framework.h"

W4_USE_UNSTRICT_INTERFACE

class W4TemplateGame : public w4::IGame
{
public:

    void onConfig() override
    {
        // todo: configure application behavior
    }

    void onStart() override
    {
        auto cam = render::getScreenCamera();
        cam->setWorldTranslation({0.f, 0, -40.f});
        cam->setFov(45.f);
        auto mat = Material::getDefault()->createInstance();
        for(int y = 0; y < 10; ++y)
            for(int x = 0; x < 10; ++x)
            {
            W4_LOG_DEBUG("create shape #%d:%d", x, y);
            auto shape = (x%2) ? Mesh::create::cube({1,1,1}) : Mesh::create::cylinder(.8, .8, 16);
            shape->setWorldTranslation({2.0f * x - 9.0f ,2.0f * y - 9.0f, 0});
            shape->setMaterialInst(mat);
            m_shapes.push_back(shape);
            render::getRoot()->addChild(shape);
        }
    }

    void onUpdate(float dt) override
    {
        float shift = -5.0;
        for(auto& shape : m_shapes)
        {
           shape->rotate(Rotator(dt*shift, dt, dt));
           shift += 0.1;
        }
    }

private:
   std::vector<Mesh::sptr> m_shapes;

};

W4_RUN(W4TemplateGame)