Difference between revisions of "Common Knowledge/ru"

From Ciliz|W4
(Updating to match new version of source page)
 
(Updating to match new version of source page)
Line 81: Line 81:
 
   Mesh::create::skybox();
 
   Mesh::create::skybox();
  
== Second Example ==
+
=== 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 ==
 
Различные меши на одном экране:
 
Различные меши на одном экране:
  

Revision as of 09:48, 27 May 2020

Эта небольшая статья содержит короткие факты по работе с движком.

Installation and Launch Info

  1. Движок разрабатывается и тестируется под OS Debian. Пользователи Windows могут установить образ Debian через WSL.
  2. Не забудьте обновить компоненты Debian перед началом работы.
  3. Для работы с репозиторием вам понадобиться Git. За ссылкой на скачивание репозитория обращайтесь к команде W4.
  4. Перед первым запуском SDK, а также после крупных обновлений, необходимо запускать скрипт настройки пререквизитов командой ./w4 --prereq. После этого необходимо перезапустить систему (или инстанс). Затем выполните команду: npm -g install serve
  5. Для сборки проекта используйте следующие команды, находясь в каталоге w4-sdk-demo:
  • Удалить результаты предыдущей сборки: ./w4 --clean
  • Собрать проект: ./w4 --build

Test 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)

В результате выполнения на экран выводится вращающийся куб.

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

Различные меши на одном экране:

#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)