JohnK

Members
  • Content count

    923
  • Joined

  • Last visited

  • Days Won

    20

JohnK last won the day on January 23

JohnK had the most liked content!

1 Follower

About JohnK

  • Rank
    Advanced Member

Contact Methods

  • Website URL
    http://babylonjsguide.github.io/

Profile Information

  • Gender
    Male
  • Location
    England, Buckinghamshire

Recent Profile Visitors

3,935 profile views
  1. Absolute positioning

    Probably worth reading the documentation on rotations and pivots. Start here http://doc.babylonjs.com/babylon101/position and follow the further reading links. In a way you answer your own question. If you want to position a mesh based on its CoG it position will always be (0, 0, 0) since the CoG moves with the mesh and the positions of everything else in the world would have to be recalculated, so you have changed the coord system. So for positioning it is best to maintain one world coord system and allow the CoG to move in the world. On the other hand since rotations generally take place about a CoG is is best to form axes local to the CoG, those in local space to calculate and perform rotations. So you need two coordinate systems for the calculations. Of course Babylon.js does all this internal work for you. Consider the two boxes in the following PG https://www.babylonjs-playground.com/#PBNUN7 In World Space the CoG for box1 is (0, 0, 0) is its position and the CoG for box2 is (4, 2, 3) also its position. To rotate box2 based on box2's CoG means to rotate box2 about the point (4, 2, 3). Take a rotation about box2's CoG of PI/4 about an axis parallel to the world axis. How do you calculate the new positions of the box corners in the world space? Well it is more straight forward to do rotations about the origin rather than an arbitrary point. In practice the only way to do rotations about an arbitrary point is to treat that point as an origin and use a different set of axes, ie those in local space, through this point as origin. Do the rotation in the local space and then calculate the world space for the corners. In Babylon.js rotations are about the local axes in local space and the engine does the corner calculations for you. Hence box2.rotation.y = Math.PI/4 is a rotation about the CoG in local space. When you need to rotate a box about some other point and not its position you need to set and use a pivot.
  2. Power impulse

    For the ball to hit exactly the place on the ground that was clicked on you need to know the acceleration due to gravity, G, that is being used in the physics engine. Given the horizontal linear velocity, V, of the ball towards the click point you can calculate the speed of the ball ||V|| and you can also calculate the horizontal distance, D, between the ball and click point. Then the time, T, to reach the click point will be found from T = D/||V||. So you now need a vertical velocity W such that after a time T the vertical displacement will be 0, this can be found using Newton's equations of motion in this case 0 = WT - 0.5GT*T. http://www.bbc.co.uk/bitesize/higher/physics/mech_matt/analyse_motion/revision/2/
  3. Сoordinates to the object

    Better? https://www.babylonjs-playground.com/#IFFDYH#4
  4. Holes in extruded shape

    One way is to merge all of the 'sideHole's into one mesh before using CSG https://www.babylonjs-playground.com/#5KCYBZ#2
  5. Сoordinates to the object

    Examining 'pick' in the console shows that 'pickedPoint' is what you need. https://www.babylonjs-playground.com/#IFFDYH#2
  6. Change edges of decahedron

    Another possibility https://www.babylonjs-playground.com/#AFXASF#9 Basically done by examining the positions of the vertices, determining which need to be moved and changing their values.
  7. Simple furMaterial

    It you do not need the animation then would the lower level mode not suit you? Note number of segments increased to "thin" fur https://www.babylonjs-playground.com/#2322Y7#20
  8. Creating Constant-Width 2D Lines

    Simplest way is probably just rotate the line about x axis https://www.babylonjs-playground.com/#FA2H7X#7
  9. Line System with a UV

    This could be adapted to change thickness along its length if needed. http://doc.babylonjs.com/samples/line2d Worth a look.
  10. Something like this? https://www.babylonjs-playground.com/#TZSWRR
  11. create ground mesh from a plane

    Hi @yokewang and welcome to the forum. @Amarth2Estel gave an excellent solution a little lost in the PG. Since you cannot change the sideOrientation to BABYLON.Mesh.DOUBLESIDE you cannot see the plane from the position of the camera. A change to camera type and position get you https://playground.babylonjs.com/#72YAXV#1
  12. The default order is YXZ locally. http://doc.babylonjs.com/babylon101/position#convention-1-local-axes https://www.babylonjs-playground.com/#8ECWTD I do remember at some point quite a time ago a comment in the code somewhere that order was a a 'to do'. The function does work correctly so it might be a good job that the order YZX is ignored. http://doc.babylonjs.com/resources/rotation_conventions#quaternions-to-euler-angles
  13. Absolute Position and Pivot Point

    It could perhaps be even more? In starting to re-write the documentation and the PG examples examples that go with it I came across a situation where a further decision needs to be considered. I will follow the issue with the reason for it. Issue Under the breaking change where only the pivot is changed I would expect the following to apply :- A box having width 8, height 4 and depth 2 and origin at (0, 0, 0) is to have a pivot set at its right front lower corner (4, -2, -1) The pivot need to be translated (4, -2, -1) so set the matrix M for this translation. however Box.setPivotMatrix(M) places the pivot at (-4, 2, 1) You can see this in the PG https://www.babylonjs-playground.com/#AGXDE#20 So to place the pivot at (4, -2, -1) requires M to be set using the negative translation (-4, 2, 1) as seen in the PG https://www.babylonjs-playground.com/#AGXDE#21 Decision Possibilities leave the function setPivotMatrix alone and ensure the documentation clearly states that that the matrix needs to use the inverse translation; change the function setPivotMatrix to work with the actual translation, if so the function setPivotPoint (and possibly getPivotPoint and getAbsolutePivotPoint) would need changing; something I haven't thought of. Reasons The original function moved the mesh and so, as in the given example, to place the pivot at the right front lower corner required the translation of the box to be in the opposite direction - see PG using stable version https://www.babylonjs-playground.com/indexstable#AGXDE#22 before translating the box back to its original position. The function setPivotMatrix still follows this procedure.