Jump to content

Rotation of car


Recommended Posts

I have a car with a 90 degree rotation in Blender on the Z axis. Which I am assuming that means the Y axis in BJS. .See attached screen grab. (the ground plane in BJS is on the X-Z plane).


I have heading data encoded in degree format (360 = NORTH, 90=EAST).  


I am using the following equation to convert degrees to radians.

        this.translate = function (datum) {            var lon = datum.geometry.coordinates[0];            var lat = datum.geometry.coordinates[1];            var y = datum.geometry.coordinates[2];            var heading = (datum.properties.heading / 360) * Math.PI;            var x = (lon - self.map.West) * self.ground.xScale;            var z = (lat- self.map.South) * self.ground.zScale;            GLOBAL.state.x = x;            GLOBAL.state.y = y;            GLOBAL.state.z = z;            GLOBAL.state.heading = heading;        }

(this is so trivial a problem and blushing to post it).

But most of the time I get a car that is rotated at odd angles. What do I not understand about the Babylon coordinate system?







Oh yes, I am using a followCamera:

        this.switchCamera = function () {            var dolly = new BABYLON.FollowCamera("FollowCam", self.scene.activeCamera.position, self.scene);            dolly.rotation = self.scene.activeCamera.rotation;            dolly.checkCollisions = true;            dolly.applyGravity = true;            dolly.ellipsoid = new BABYLON.Vector3(1, 1, 1); // collision ellipsoid            dolly.heightOffset = 60; //height above the object            dolly.rotationOffset = 0; // follow from the rear            dolly.radius = 125; // how far from the object            dolly.cameraAcceleration = 0.05 // how fast to move            dolly.maxCameraSpeed = 20 // speed limit            dolly.target = self.car;            self.scene.activeCamera.detachControl(self.canvas);            self.scene.activeCamera = dolly;            self.scene.activeCamera.attachControl(self.canvas);        }


Link to comment
Share on other sites

Hi again DrYSG... good to see you, and it looks like we're going racing, eh?  :)


This is not trivial, so don't feel embarrassed at all.  There's been MANY posts on the forum about 'move' and 'moveWithCollision' and directions and quaternions.  I'm not very experienced with these things.  Iceman has done some miracle-worker stuff with directions and animated-turns... so check out his threads.  So has... umm... digitalhilsone?  Not sure about that name.


I once did a really bad flight sim... might be something in there that can help.  There's some flat-turning going-on in there... and the throttle is based upon elapsed time.  Not too bad.


Dr... are using a physics engine?  Have you got a hidden jet engine on the back of that car... and using applyImpulse to power that thing?  If so, quaternion crap is needed, which means you MIGHT need to set "export quaternions" (or a similar setting) in your Blender exporter panel (if such a thing is available).  I've never exported anything from Blender... so I'm operating in the blind.  (What a lamer I am, eh?)  ;)


And, lastly, can you replicate this problem/issue... in the Babylon Playground (using a stick instead of a car model)?  That would be good.


You are actually dealing with two separate steps here.  #1 - Modeling and export, #2 - Further translating, rotating, targeting, impulsing, etc... in BJS scene (driving/jumping).


So, step one, make sure you have a great export.  After scene render of model, check your axes.  Use a standard (free) camera for right now... and ideally, aim the cam AND your car toward +Z.  Get your scene "squared-up" with Blender... and make sure the export-to-scene happens correctly (with quaternions, why not).  :)  Also, you may want to bake a rotation-transformation into your model.  In Blender... all your rotation settings would be 0, but your car would still be facing the way you wish... because you transform the vertices... at gunpoint.  Transformation baking is also available in BJS... usable just after import, if wanted.  A user named Gryff is pretty hot with Blender... he might know how to null/bake rotations in Blender.


After all that... begin your study of how to propel and how to turn.


In a way... the bad flight sim is good place to study propelling and turning.  Grab a zip, take it home.  Or make adjustments, press RUN over and over, make a fresh SAVE and paste it's new URL here... we'll study it.  Change my stupid airplane into a stupid car, and SAVE, and send us the playground URL... and have a blast... but let us have a blast, too.   (Where we all can experiment with your #2 issue.)  :o


Keep in mind that this forum is mostly guys, so if you put FOUR particleSystems on the back of your car... smoke, fire, soot, and broken engine... and decide to power your car with applyImpulse (jet engine)... and then save THAT gorgeous playground as the testing playground for the forum guys...  YOU WILL GET LOTS OF INTEREST. :D


(Guys like things that have fire-breathing jet engines attached.)  :)


Ok, that's enough for today.  DrYSG's flame-belchin' ramp-jumpin' funnycar.  Cooooooool.  :)

Link to comment
Share on other sites



do u know how to rotate the front tires of a car when it's running left or right???

        if (this.keys.a) {            if (this.speed > 0)                this.carBody.rotation.y -= 0.03;            else if(this.speed < 0)                this.carBody.rotation.y += 0.03;            this.tireFL.rotation.z = -Math.PI / 6;            this.tireFR.rotation.z = -Math.PI / 6;        } else if (this.keys.d) {            if (this.speed > 0)                this.carBody.rotation.y += 0.03;            else if(this.speed < 0)                this.carBody.rotation.y -= 0.03;            this.tireFL.rotation.z = Math.PI / 6;            this.tireFR.rotation.z = Math.PI / 6;        } else {            this.tireFL.rotation.z = 0;            this.tireFR.rotation.z = 0;        }        for (var i = 0; i < this.allTires.length; i++) {            this.allTires[i].rotation.x += this.speed;        }

when the scene first loaded. press A or D can let the front tire rotate left or right ok....(this.tireFL.rotation.z = -Math.PI / 6;)



But after the car run (this.allTires.rotation.x += this.speed;),  the front tires can not rotate correctly...

Link to comment
Share on other sites

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.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...