Difference between revisions of "Common Knowledge/en"

From Ciliz|W4
(Created page with "This tiny article contains some facts about working with the engine.")
 
(Created page with "# The engine is developed and tested under OS Debian. Windows users can install the Debian image through WSL. # Contact the W4 team for obtaining the project repository. # Rem...")
Line 1: Line 1:
 
This tiny article contains some facts about working with the engine.
 
This tiny article contains some facts about working with the engine.
 
== Installation and Launch Info ==
 
== Installation and Launch Info ==
# Движок разрабатывается и тестируется под OS Debian. Пользователи Windows могут установить образ Debian через WSL.
+
# The engine is developed and tested under OS Debian. Windows users can install the Debian image through WSL.
# Не забудьте обновить компоненты Debian перед началом работы.
+
# Contact the W4 team for obtaining the project repository.
# Для работы с репозиторием вам понадобиться Git. За ссылкой на скачивание репозитория обращайтесь к команде W4.
+
# Remember to update your OS Debian components before you get started.
# Перед первым запуском SDK, а также после крупных обновлений, необходимо запускать скрипт настройки пререквизитов командой ./w4 --prereq. После этого необходимо перезапустить систему (или инстанс). Затем выполните команду: npm -g install serve
+
# Before starting the SDK for the first time, as well as after major updates, run the prerequisite configuration script with the ./w4 --prereq command. After that, restart the OS (or instance). And only then run: npm -g install serve
# Для сборки проекта используйте следующие команды, находясь в каталоге w4-sdk-demo:
+
# To build the project, use the following commands:
* Удалить результаты предыдущей сборки: ./w4 --clean
+
* Delete the results of the previous build: ./w4 --clean
* Собрать проект: ./w4 --build
+
* Build the project: ./w4 --build
  
 
== Test Example ==
 
== Test Example ==

Revision as of 15:03, 26 May 2020

This tiny article contains some facts about working with the engine.

Installation and Launch Info

  1. The engine is developed and tested under OS Debian. Windows users can install the Debian image through WSL.
  2. Contact the W4 team for obtaining the project repository.
  3. Remember to update your OS Debian components before you get started.
  4. Before starting the SDK for the first time, as well as after major updates, run the prerequisite configuration script with the ./w4 --prereq command. After that, restart the OS (or instance). And only then run: npm -g install serve
  5. To build the project, use the following commands:
  • Delete the results of the previous build: ./w4 --clean
  • Build the project: ./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();

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