MattePatte

Members
  • Content Count

    11
  • Joined

  • Last visited

  1. Look what i found!! BABYLON.Tools.GetFps().toFixed(); It works perfect.
  2. Hello friends! I don't understand how to use engine.beginFrame(). It says in the documentation that it should measure the Frames Per Second but i don't understand how it works. If anyone could show me a example that would have been awesome. I have tried to measure the FPS by my self and it looks something like this. var lastCalledTime;var fps;var stop = 0; var renderLoop = function () { // Start new frame if(!lastCalledTime) { lastCalledTime = new Date().getTime(); fps = 0; BABYLON.Tools.QueueNewFrame(renderLoop); return; } delta = (new Date().getTime() - lastCalledTime)/1000; lastCalledTime = new Date().getTime(); fps = 1/delta; // a stop variable since it hard to se the fps when it's displayed 60 times per //second, if(stop == 30){ // a div element to display the fps fpsDiv.innerHTML = parseInt(fps); stop = 0; } engine.beginFrame(); scene.render(); // Present engine.endFrame(); // Register new frame BABYLON.Tools.QueueNewFrame(renderLoop); stop++;};It shows a frame rate between 60 and 0 but it's usually quite low around 16 FPS. I have a piece of shit computer so that doesn't surprise me, but i want to be sure that i really measure the fps. Thanks!
  3. Hi realizer I think you are looking for the dispose function. box.dispose()Have a greate day!
  4. Thanks for the ideas Wingnut and the optimization qwaenael. But i still haven't solved the problem. I can't use the arcRotateCamera since it's locked to look at a fixed point. What i am looking for is a camera which is exactly like the FreeCamera except you don't have to hold the left mouse key to rotate it. I have managed with the rotation of the camera, but not when i want it to move forward, backwards, left and right. This post describes exactly what i want to do. http://www-rohan.sdsu.edu/~stewart/cs583/LearningXNA3_lects/Lect15_Ch11_CreateFirstPersonCamera.html The problem is that the camera.cameraDirection don't updates when i am rotating the rotation of the camera. I need a Vector that always points forward, in the direction i the camera is looking. This should be the code, except it's not written in JavaScript. if (Keyboard.GetState( ).IsKeyDown(Keys.W)) cameraPosition += cameraDirection * speed; if (Keyboard.GetState( ).IsKeyDown(Keys.S)) cameraPosition -= cameraDirection * speed; // Move side to side if (Keyboard.GetState( ).IsKeyDown(Keys.A)) cameraPosition += Vector3.Cross(cameraUp, cameraDirection) * speed; if (Keyboard.GetState( ).IsKeyDown(Keys.D)) cameraPosition -= Vector3.Cross(cameraUp, cameraDirection) * speed;
  5. I didn't manage as well as i thought. The camera.cameraDirection don't updates when i am updating the camera.rotation. I just want to move the camera forward when i am pressing the W key.
  6. I am blind and didn't found the cameraDirection property in the Documentation. So if anyone is interested building a FPS game the controls is the following: //Pressing Wcamera.cameraDirection= camera.cameraDirection.add(new BABYLON.Vector3(0,0,0.1));//Pressing Scamera.cameraDirection= camera.cameraDirection.add(new BABYLON.Vector3(0,0,-0.1));//Pressing Acamera.cameraDirection= camera.cameraDirection.add(new BABYLON.Vector3(-0.1,0,0)); //Pressing D camera.cameraDirection= camera.cameraDirection.add(new BABYLON.Vector3(0.1,0,0));//The rotation is done by creating mouse variable:var mouse = new BABYLON.Vector2();function onDocumentMouseMove( event ) { mouse.x = ( event.clientX / window.innerWidth ) * 2 - 1; mouse.y = -( event.clientY / window.innerHeight ) * 2 + 1;}function yourRenderFunction(){ if(mouse.x>0.7 || mouse.x<-0.7 || mouse.y>0.7 || mouse.y<-0.7){ camera.rotation = camera.rotation.add( new BABYLON.Vector3((-mouse.y)/100,0,0)); camera.rotation = camera.rotation.add( new BABYLON.Vector3(0,(mouse.x)/100,0)); }}Works fine for me.
  7. Hi! I am having some problems that i think i can solve but i am wondering if there is any simpler solutions. I want an FPS like camera i am not happy with the standard controls of the FreeCamera even though i have changed the arrow keys to W,A,S,D keys. I don't like that you have to press the left mouse key to rotate it. Is it possible only using moveCamera controls and skip the rotation part of a FreeCamera? If it's not, can i move the camera depending on it's rotation so it always moves forward when pressing the W key. I am also wondering if anyone nows a easy way of implementing a drag and drop for meshes? I just want recommendations of functions and links, don't solve the algorithms for me.
  8. Thanks Wingnut! I will start learning about quaternion.
  9. I am very bad rotating meshes. As i mentioned earlier the objective is to rotate the mesh without removing it. This is the code. shape = new BABYLON.Mesh.CreateBox("box",3,scene,true);shape.scaling.x = 5;shape.scaling.y = 0.2;shape.scaling.z = 5;shape.setPhysicsState({ impostor: BABYLON.PhysicsEngine.BoxImpostor, mass: 0, friction: 0.5,restitution: 0.7 });shape.rotate(BABYLON.Axis.X, Math.PI/4, BABYLON.Space.LOCAL);shape.translate(BABYLON.Axis.X, 4, BABYLON.Space.WORLD);The mesh don't rotate or moves in this case. But if i rotate and translates before adding the physics to the mesh it works. Do i have to remove the mesh and then add it to rotate it or is there a solution for rotating it without removing it?
  10. Excellent question. Just took a file named babylon.js in when downloaded the repository from github. I can see now there is a JavaScript file called babylon.1.9.0.js and that it is the one that has the functionalists for rotate and translate. So i think you have solved the problem for me thank you!
  11. Hi! I have problems changing the rotation and position of meshes when i have added physics to them. I have taken a look at the tutorial (https://github.com/BabylonJS/Babylon.js/wiki/How-to-handle-rotations-and-translations) but still haven't found a solution. I have manage to change the rotation and position before i have added physics to the mesh but i would rather change the rotation and position without removing and adding the mesh every time i want to change it's position and rotation. I think the problem is that i don't manage to get these two function to work. mesh.rotate(BABYLON.Axis.X, 1.0, BABYLON.Space.LOCAL);mesh.translate(BABYLON.Axis.X, 1.0, BABYLON.Space.WORLD); Saying that property.X is undefined. Any suggestions and comments are more then welcome!