Babylonjs-basic-elements-rotation

提供:Dev Guides
移動先:案内検索

BabylonJS-回転

以下に示すデモでは、上で見たボックスを回転させます。

Demo

<!doctype html>
<html>
   <head>
      <meta charset = "utf-8">
      <title>BabylonJs - Basic Element-Creating Scene</title>
      <script src = "babylon.js"></script>
      <style>
         canvas {width: 100%; height: 100%;}
      </style>
   </head>

   <body>
      <canvas id = "renderCanvas"></canvas>
      <script type = "text/javascript">
         var canvas = document.getElementById("renderCanvas");
         var engine = new BABYLON.Engine(canvas, true);
         var createScene  = function() {
            var scene = new BABYLON.Scene(engine);
            scene.clearColor = new BABYLON.Color3(0, 1, 0);

            var camera = new BABYLON.ArcRotateCamera("Camera", 1, 0.8, 10, new BABYLON.Vector3(0, 0, 0), scene);
            scene.activeCamera.attachControl(canvas);

            var light = new BABYLON.PointLight("Omni", new BABYLON.Vector3(0, 100, 100), scene);

            var boxa = BABYLON.Mesh.CreateBox("BoxA", 1.0, scene);
            boxa.position = new BABYLON.Vector3(0,0.5,0);

            var boxb = BABYLON.Mesh.CreateBox("BoxB", 1.0, scene);
            boxb.position = new BABYLON.Vector3(3,0.5,0);
            boxb.rotation = new BABYLON.Vector3(Math.PI/2,0.5,0);

            var boxc = BABYLON.Mesh.CreateBox("BoxC", 1.0, scene);
            boxc.position = new BABYLON.Vector3(-3,0.5,0);
            boxc.rotation = new BABYLON.Vector3(Math.PI/2,0.5,0);

            var boxd = BABYLON.Mesh.CreateBox("BoxD", 1.0, scene);
            boxd.position = new BABYLON.Vector3(0,0.5,3);
            boxd.rotation = new BABYLON.Vector3(0,0.5,Math.PI/2);

            var boxe = BABYLON.Mesh.CreateBox("BoxE", 1.0, scene);
            boxe.position = new BABYLON.Vector3(0,0.5,-3);
            boxe.rotation = new BABYLON.Vector3(0,0.5,Math.PI/2);

            var ground = BABYLON.Mesh.CreateGround("ground1", 10, 6, 2, scene);
            ground.position = new BABYLON.Vector3(0,0,0);
            return scene;
         };
         var scene = createScene();
         engine.runRenderLoop(function() {
            scene.render();
         });
      </script>
   </body>
</html>

上記のコードがどのように機能するかを確認するには、次の例を検討してください-

基本的な要素の回転

説明

配置に* new BABYLON.Vector3(x、y、z)を使用した方法で、同じ方法で回転を適用できます。 ここでは、 new BABYLON.Vector3(x、y、z)を使用して回転を適用するか、 *box.rotation.x、box.rotation.y、box.rotation.z を使用できます。

回転するには、角度をラジアンで指定する必要があります。 1度は等しい 0.01745329252ラジアン:1°=π/180°= 0.01745329252 rad 。 たとえば、* boxb.rotation = new BABYLON.Vector3(Math.PI/2,0.5,0)*;