jerome Posted June 3, 2015 Share Posted June 3, 2015 Hi, I'm currently coding a PG path3D use case. I would like to show a rollercoaster : http://www.babylonjs-playground.com/#1JPPXD(path3D model with tangents, normals, binormals on left, final rollercoaster mesh on right) Actually, I would like to do something like this threejs demo when you click on "pline animation ON" http://threejs.org/examples/#webgl_geometry_extrude_splines. As I didn't investigate BJS cameras so far, I wonder what kind of camera I should opt for : a TargetCamera ? My needs are :the cam can be positioned dynamically in space, this position can't be modified by user controls (keyboard, mouse)the cam can aim a target (vector3) or else (don't mind wingy ) can aim with an axis (vector3)the cam can be rotated/aligned in space, so I could make follow the rollercoaster rails curve... or maybe should I set it in a rotated parent mesh ?Any clues appreciated [EDIT : in the threejs example, the cam doesn't rotate with the curve] Wingnut 1 Quote Link to comment Share on other sites More sharing options...
RaananW Posted June 3, 2015 Share Posted June 3, 2015 What about the Follow Camera? would work great for a roller coaster. Quote Link to comment Share on other sites More sharing options...
jerome Posted June 3, 2015 Author Share Posted June 3, 2015 http://babylondoc.azurewebsites.net/page.php?p=24874 I can understand what are position and rotation as for any other meshes. I don't understand what is cameraRotation, neither the cameraDirection (I guess it's something like target - position ?)What about speed ?Does this cam moves alone ..? Quote Link to comment Share on other sites More sharing options...
RaananW Posted June 3, 2015 Share Posted June 3, 2015 from the docs: FollowCamera - Forum user AlexB was kind enough to contribute the handy FollowCamera to Babylon.js. (Thanks AlexB!) This camera is specifically designed to follow any scene item with a .position... as it moves. It can be set to follow from the rear, from the front, or from any angle. Its follow distance and movement speeds can be set, as well.I personally never used it and never tested it so.... no idea how well it works. But it works for sure :-) Quote Link to comment Share on other sites More sharing options...
jerome Posted June 3, 2015 Author Share Posted June 3, 2015 As far as I understand, the follow camera ... follows a mesh at certain distance. I want to set my camera at a given position because I compute this position according to the path3D. Idem for the camera target ... Quote Link to comment Share on other sites More sharing options...
Temechon Posted June 3, 2015 Share Posted June 3, 2015 I would do the following:- Create a box at a given position- Create a followCamera, which target is the box above- Set the box invisible- Move the box according to the path3D, the camera will automatically follow. And you're done.The followCamera is easy to set up:camera.radius = 4;camera.heightOffset = 1.5;The camera will rotate accordingly to its target. Quote Link to comment Share on other sites More sharing options...
jerome Posted June 3, 2015 Author Share Posted June 3, 2015 Ok thank youwill try this but isn't there another way simpler ? without any follow camera but a simple camera ? Quote Link to comment Share on other sites More sharing options...
Temechon Posted June 3, 2015 Share Posted June 3, 2015 Playground : http://www.babylonjs-playground.com/#1JPPXD#1 I guess a FreeCamera would do the trick as well. Just set camera.lookAt(position) to update the rotation. Wingnut 1 Quote Link to comment Share on other sites More sharing options...
jerome Posted June 3, 2015 Author Share Posted June 3, 2015 cam not tested yetbut added a wagon (your future invisible box mesh) : http://www.babylonjs-playground.com/#1JPPXD#2 this demo both features Path3D and RotationFromAxis (my math babies ) Quote Link to comment Share on other sites More sharing options...
jerome Posted June 3, 2015 Author Share Posted June 3, 2015 Does anyone know if cameraDirection property of the TargetCamera object is the point aimed (coordinates of the point in space) at OR the direction axis (vector) ? Quote Link to comment Share on other sites More sharing options...
Temechon Posted June 3, 2015 Share Posted June 3, 2015 I think it's the direction axis. The point aimed is the target. Quote Link to comment Share on other sites More sharing options...
jerome Posted June 3, 2015 Author Share Posted June 3, 2015 I hadn't seen your PG Temechon ! really good !!! for now, I'm investigating simply the TargetCamera...I guess I'm almost done despite I don't understand what is the cameraRotation property please, don't vomit : http://www.babylonjs-playground.com/#1JPPXD#3 the cam is looking here 12 points farther on the rails Quote Link to comment Share on other sites More sharing options...
jerome Posted June 3, 2015 Author Share Posted June 3, 2015 mmmh...I really don't get how cameraDirection works (added interpolation now, so the movement is smoother) Look at this : http://www.babylonjs-playground.com/#1JPPXD#4line 124 : the camera direction is set towards the origin what is a point on the ground where a wagon leaves.Yet the camera, positioned at pos, doesn't look toward the wagon. Am I missing something ? Quote Link to comment Share on other sites More sharing options...
jerome Posted June 3, 2015 Author Share Posted June 3, 2015 seems to work better when using setTarget instead of this weird cameraDirection: http://www.babylonjs-playground.com/#1JPPXD#5here, the target is a point at 20 further (dt line 93) and the interpolation step is only 2 (line 99)If you want more steps to go from segment to the next one, then the camera seems to shake (step = 10 ) : http://www.babylonjs-playground.com/#1JPPXD#6 grrrrr... camera problems !!! the path and animation seem to be working I probably use the wrong camera or the wrong property values... Quote Link to comment Share on other sites More sharing options...
JCPalmer Posted June 3, 2015 Share Posted June 3, 2015 If you wish to do something like this:https://googledrive.com/host/0B6-s6ZjHyEwUfkRGTUVVTUxaT01UZUlieGdCODF1blFZZHJFMnRJUHBpcG1KcnBjUVluYXc, then use either targetcam or freecam with no attach. You need to set camera.lockedTarget on the mesh to aim at. I think you also still need to shake up camera every time mesh moves, by calling camera._getViewMatrix() jerome 1 Quote Link to comment Share on other sites More sharing options...
jerome Posted June 4, 2015 Author Share Posted June 4, 2015 Well, my camera is moving along the rollercoaster rails and it looks (choice to be done in the code) either at a certain number of points farther on the rails, either in the direction of the current tangent to the rails (vector). So there is no real locked target, like a distant moving or static mesh, since the camera direction changes according to its own position only. What am I suppose to do with the cam viewMatrix then ? Quote Link to comment Share on other sites More sharing options...
jerome Posted June 4, 2015 Author Share Posted June 4, 2015 Since I can't have the cam working as I expect for now, here is a first roller-coaster demo (no subjective POV) introducing some new BJS features for 2.1 I'm proud to have contributed to : Curve3D + hermite splinepath3DextrusionrotationFromAxis http://www.babylonjs-playground.com/#21EWAB still investigating to have some smooth subjective view Temechon 1 Quote Link to comment Share on other sites More sharing options...
jerome Posted June 4, 2015 Author Share Posted June 4, 2015 just tried with a follow camera : http://www.babylonjs-playground.com/#21EWAB#1it's still shaky according to the step value (line 179) despite I forced a followCamera._computeViewMatrix each frame don't get why any help appreciated about smooth cam viewing Quote Link to comment Share on other sites More sharing options...
jerome Posted June 4, 2015 Author Share Posted June 4, 2015 still shaky with a targetCam also : http://www.babylonjs-playground.com/#21EWAB#3 Quote Link to comment Share on other sites More sharing options...
jerome Posted June 4, 2015 Author Share Posted June 4, 2015 As far I understand, the lag occurs each time the value of the target given to setTarget() changes.Maybe is it a too big difference between two successive values ..? I would like to use cameraDirection instead, but it doesn't behave as I expect (I think we give an axis) Quote Link to comment Share on other sites More sharing options...
jerome Posted June 4, 2015 Author Share Posted June 4, 2015 doesn't change anything if the target moves just slightly between two frames : shaky need another lead ... Quote Link to comment Share on other sites More sharing options...
Temechon Posted June 4, 2015 Share Posted June 4, 2015 Yiiiiha !! http://www.babylonjs-playground.com/#21EWAB#4 Quote Link to comment Share on other sites More sharing options...
jerome Posted June 4, 2015 Author Share Posted June 4, 2015 Waaaaooowwwww !!!Excellent I need to understand how you did since I feel stuck in this stuff Quote Link to comment Share on other sites More sharing options...
jerome Posted June 4, 2015 Author Share Posted June 4, 2015 subjective view working now with Temechon fixing : http://www.babylonjs-playground.com/#21EWAB#5 too hot here, my brain is boiling, I didn't notice I normalize unneeded vectors Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted June 4, 2015 Share Posted June 4, 2015 Lol excellent! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.