Difference between revisions of "Common Knowledge/en"

From Ciliz|W4
 
(9 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
This brief article contains some basic facts about working with the engine.
 
This brief article contains some basic facts about working with the engine.
 
== Installation and Launch Info ==
 
== Installation and Launch Info ==
<div class="mw-translate-fuzzy">
+
# The engine is developed and tested under OS Debian. Windows users can install the Debian image through WSL.  
# 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.
 
# Contact the W4 team for obtaining the project repository.
 
# Remember to update your OS Debian components before you get started.
 
# Remember to update your OS Debian components before you get started.
# 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).
+
# 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.
3) Run: npm -g install serve.
 
 
 
 
# To build the project, use the following commands:
 
# To build the project, use the following commands:
 
* Delete the results of the previous build: ./w4 --clean
 
* Delete the results of the previous build: ./w4 --clean
 
* Build the project: ./w4 --build
 
* Build the project: ./w4 --build
</div>
 
  
 
== Test Example ==
 
== Test Example ==
 
Use the following example:
 
Use the following example:
  
 +
<syntaxhighlight lang="c++">
 
  #include "W4Framework.h"
 
  #include "W4Framework.h"
 
   
 
   
Line 47: Line 44:
 
  };
 
  };
 
  W4_RUN(W4TemplateGame)
 
  W4_RUN(W4TemplateGame)
 +
</syntaxhighlight>
  
 
Expected result: A spinning cube appears.
 
Expected result: A spinning cube appears.
Line 52: Line 50:
 
== Interfaces ==
 
== Interfaces ==
 
=== Interface IGame ===
 
=== Interface IGame ===
 
+
<syntaxhighlight lang="c++">
 
  virtual void onConfig()         
 
  virtual void onConfig()         
 
  virtual void onStart()           
 
  virtual void onStart()           
Line 61: Line 59:
 
  virtual void onLost()           
 
  virtual void onLost()           
 
  virtual void onRestore()
 
  virtual void onRestore()
 +
</syntaxhighlight>
  
 
=== Basic Camera Interface ===
 
=== Basic Camera Interface ===
 
+
<syntaxhighlight lang="c++">
 
  void setFov(float v);
 
  void setFov(float v);
 
  void setAspect(float v);
 
  void setAspect(float v);
Line 70: Line 69:
 
  void setClearColor(const math::vec4& v);
 
  void setClearColor(const math::vec4& v);
 
  void setClearMask(ClearMask v);
 
  void setClearMask(ClearMask v);
 +
</syntaxhighlight>
  
 
=== Mesh Generators ===
 
=== Mesh Generators ===
 
+
<syntaxhighlight lang="c++">
 
   Mesh::create::cube(const math::vec3& size);
 
   Mesh::create::cube(const math::vec3& size);
 
   Mesh::create::mappedCube(const math::vec3& size);
 
   Mesh::create::mappedCube(const math::vec3& size);
Line 84: Line 84:
 
   Mesh::create::torus(float radius, float tube, uint32_t radialSegments, uint32_t tubularSegments, float arc);
 
   Mesh::create::torus(float radius, float tube, uint32_t radialSegments, uint32_t tubularSegments, float arc);
 
   Mesh::create::skybox();
 
   Mesh::create::skybox();
 +
</syntaxhighlight>
  
 
=== Node Hierarchy Interface ===
 
=== Node Hierarchy Interface ===
 +
<syntaxhighlight lang="c++">
 
  sptr<RootNode> getRoot() const;
 
  sptr<RootNode> getRoot() const;
 
  sptr getParent() const;
 
  sptr getParent() const;
Line 103: Line 105:
 
  std::list<sptr> findChildren(std::string const&) const;
 
  std::list<sptr> findChildren(std::string const&) const;
 
  std::list<sptr> findChildrenRecursive(std::string const&) const;
 
  std::list<sptr> findChildrenRecursive(std::string const&) const;
 +
</syntaxhighlight>
  
 
== Another Example ==
 
== Another Example ==
 
Showing various meshes:
 
Showing various meshes:
 
+
<syntaxhighlight lang="c++">
 
  #include "W4Framework.h"
 
  #include "W4Framework.h"
 
   
 
   
Line 154: Line 157:
 
   
 
   
 
  W4_RUN(W4TemplateGame)
 
  W4_RUN(W4TemplateGame)
 +
</syntaxhighlight>

Latest revision as of 13:16, 1 June 2020

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)