Guest User

Untitled

a guest
May 9th, 2020
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.46 KB | None | 0 0
  1. // --------------------------------------------------------------------------------------
  2. //
  3. // Infinity 3D Web browser Web Assembly secure scripting interface example.
  4. //
  5. // Hello world in 3D is basically a spinning cube :)
  6. //
  7. // --------------------------------------------------------------------------------------
  8.  
  9. #include <infinity.h>
  10.  
  11. #include <math.h>
  12.  
  13. using namespace Infinity;
  14.  
  15.  
  16. class Program
  17. {
  18. public:
  19. Program()
  20. {
  21. m_zone = nullptr;
  22. m_item_node = nullptr;
  23. }
  24.  
  25. uint32_t Init()
  26. {
  27. m_zone = new Zone;
  28.  
  29. SceneGraph *scene = m_zone->GetScene();
  30.  
  31. Node *scene_root = scene->GetRoot();
  32. m_item_node = scene->CreateNode(scene_root);
  33.  
  34. auto item_object = scene->CreateObject(m_item_node);
  35.  
  36. auto item_geometry = m_zone->Find("item.xsg");
  37. item_object->SetGeometry(item_geometry);
  38.  
  39. Vector3 v;
  40. v.x = 0; v.y = 0; v.z = 10;
  41. m_item_node->SetPosition(v);
  42.  
  43. return 1;
  44. }
  45.  
  46. uint32_t Process(float current_time)
  47. {
  48. // Spin teh cube :)
  49.  
  50. const float radius = 10;
  51. float speed = 1;
  52. float angle = speed * current_time;
  53.  
  54. Vector3 v;
  55. v.x = (float) sin(angle);
  56. v.y = (float) cos(angle);
  57. v.z = 10;
  58. m_item_node->SetPosition(v);
  59.  
  60. return 1;
  61. }
  62.  
  63. uint32_t Terminate()
  64. {
  65. // Zap our stuff here.
  66. delete m_zone;
  67. return 1;
  68. }
  69.  
  70.  
  71. Zone *m_zone;
  72. Node *m_item_node;
  73. };
  74.  
  75.  
  76. // Include this after program definition.
  77. #include <inf_bootstrap.h>
Advertisement
Add Comment
Please, Sign In to add comment