Common Knowledge/en

From Ciliz|W4
This page is a translated version of the page Common Knowledge and the translation is 100% complete.

This brief article contains some basic 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 it is required to fulfill the following steps accordingly: 1 Run the prerequisite configuration script with the ./w4 --prereq command; 2 Restart the OS (or instance); 3 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

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)