correct scale, vectors

Software: Away3D 4.x

Avatar
TrueSign, Member
Posted: 30 November 2012 08:16 PM   Total Posts: 57

Hi,

I’m working on AwayPhysics for a first time. I was looking for any tutorials and there is not too much on the internet about that. I know that the newest version is based on bullet engine. I tried to find something there but without any results. My projects:
http://truesign.ie/projects/roulette/index.html
As you can see there, collision detection is now right. I played with these properties:

_physicsWorld.gravity = new Vector3D(0, -150);
_physicsWorld.scaling 80;

var 
sphereVector:Vector3D = new Vector3D(06050);
_sphereShape = new AWPSphereShape(5);
sphereBody.position sphereVector;
sphereBody.ccdSweptSphereRadius 0.01;
sphereBody.ccdMotionThreshold 0.01

Few questions here:
1) When I set sphereBody.position to sphereVector my ball is moving constantly in that direction. I just want to set up starting position, not a movement direction. I saw there is no such a thing in examples. In examples when position is set up, ball stays in place.
2) on my projects ball is not moving down. It’s pushed away from the mesh. I played with ccdSweptSphereRadius and ccdMotionThreshold and _physicsWorld.scaling and sometimes ball it just stuck in the air, sometime it’s goes through meshes. What is the relation between that ccd’s properties? I was playing with that all day now, and still can’t find good solution.
3) I found that mesh sizes have influence on the whole engine. Is there a proper size for meshes to make this this work properly? My ball mesh is in 6 size, and on examples they use 100 size ball. I have tried to scale everything up but I couldn’t find correct set then.

   

Yang Li, Administrator
Posted: 01 December 2012 03:03 AM   Total Posts: 80   [ # 1 ]

How do you rotate the roulette wheel? should use applyTorque or set angularVelocity, Otherwise the ball will not collide with wheel.

 

   

Avatar
TrueSign, Member
Posted: 01 December 2012 12:59 PM   Total Posts: 57   [ # 2 ]

Thanks Yang Li for your reply.
I use _board.rotationY += 1;

I have tried applyTorque and angularVelocity and roullete is not rotating. I found this thread: http://away3d.com/forum/viewthread/3218/ and I tried different techniques from there and only one working is:

var mtx:Matrix3D boardBody.transform.clone();
mtx.prependRotation(1Vector3D.Y_AXIS);
boardBody.transform mtx

Should I use applyTorque or angularVelocity in enterFrame? I have tried both ways. Maybe there is something wrong with me rigidBody setup:

_board event.asset as Mesh;
_board.material _boardMaterial;
_wholeScene.addChild(_board);
boardShape = new AWPBvhTriangleMeshShape(_board.geometry);
boardBody = new AWPRigidBody(boardShape_board0);
_physicsWorld.addRigidBody(boardBody); 

 

   

Yang Li, Administrator
Posted: 01 December 2012 04:14 PM   Total Posts: 80   [ # 3 ]

AWPBvhTriangleMeshShape is a static body, it can’t use applyTorque and angularVelocity, you should use a dynamic rigid body instead, for the wheel you can use the compound shape, and set its linearFactor = new Vector3d(0,0,0), set angularFactor = new Vector3d(0,1,0), to fix position and rotation, then set its angularVelocity to rotate around y axis.

 

   

Avatar
TrueSign, Member
Posted: 01 December 2012 04:20 PM   Total Posts: 57   [ # 4 ]

I will test it. Thanks.

BTW: I found something wrong with my meshes. Or I think it’s wrong. I copied my assets to one of the awayPhysics examples and I found that:
http://truesign.ie/projects/physicsTest/
That green lines are very weird. So the problem here is my mesh? How can I solve that? (in attachment my shape - it’s not so complex)
Also, when I scale entire mesh up, that green line stays in a normal scale. Can I scale rigid body as well?

 

   

Avatar
TrueSign, Member
Posted: 01 December 2012 04:29 PM   Total Posts: 57   [ # 5 ]

That compound shape should be build from available basic shapes right?
I can use cylinder for that centre part, and plane for that lower green part. But what can I use for that outer part? Inverted cylinder? Can I use something like that?

 

   

Yang Li, Administrator
Posted: 02 December 2012 03:13 AM   Total Posts: 80   [ # 6 ]

you are using a old version of awayphysics, you need update to lastest code: https://github.com/away3d/awayphysics-core-fp11/tree/dev


Here is another rigid body shape AWPGImpactMeshShape, it’s similar with AWPConvexHullShape but support concave. it have some bugs currently, but create roulette should be fine.

 

File Attachments
AWPGImpactMeshShape.zip  (File Size: 605KB - Downloads: 322)
   

Avatar
TrueSign, Member
Posted: 03 December 2012 11:19 AM   Total Posts: 57   [ # 7 ]

Thanks once again for help.
I haven’t used AWPGImpactMeshShape but I build up compound shape from many other basic shapes: cones, planes, boxes.
And it’s working! http://truesign.ie/projects/physicsTest/
However applyTorque or angularVelocity still doesn’t work. I have to use boardBody.transform = Matrix3D to rotate wheel.

Few more things I need to work out though. On my link I faked circular ball motion at the beginning with:
(in enterframe)

var rad:Number angle * (Math.PI 180);
_ball.radius Math.cos(rad);
_ball.radius Math.sin(rad);
angle += 4

You can click on START btn to release ball from that movement. I used this:

var _x:Number Math.round(_ball.x);
var 
_z:Number Math.round(_ball.z);

var 
pos Vector3D = new Vector3D(_x5_z);

var 
rad:Number = (angle 5) * (Math.PI 180);
_x Math.round(147 Math.cos(rad));
_z Math.round(147 Math.sin(rad));
var 
mpos Vector3D = new Vector3D(_x5_z);

impulse mpos.subtract(pos);
impulse.normalize();
impulse.scaleBy(10);

sphereBody.applyCentralImpulse(impulse); 

Basically I’m checking for x and z position in angle + 5 to determine the impulse vector. But as you can see on my example it’s not working.

How I can use force or impulse to make ball moving around wheel?

 

   

Avatar
TrueSign, Member
Posted: 03 December 2012 11:51 AM   Total Posts: 57   [ # 8 ]

Ok. Ball force fixed already. I had a plane that collides somehow with my ball.

 

   

Avatar
TrueSign, Member
Posted: 03 December 2012 04:26 PM   Total Posts: 57   [ # 9 ]

One more thing before I finish. How to calculate angle in that moving objects ?

I pushed all numbers from wheel to an array. 37 number in total gives 9.73 angle for each number.

var ballAngle:Number Math.round(Math.atan2(_ball.z_ball.x) * (180 Math.PI));
if (
ballAngle 0{
 ballAngle 
*= -1;
 
temp 180 ballAngle;
 
ballAngle 180 temp;
}
ballAngle 
-= 84// shifted to match correct number
if (ballAngle 0{
 ballAngle 
+= 360;
}
var pickedNumber:uint Math.roundballAngle 9.73);
trace("picked number: ",arrayNumbers[pickedNumber]); 

and it’s working fine without wheel rotation. But board rotation is changing every frame and I have to subtract that angle from my ball angle and calculate that is out of my skills I think. I have tried many different methods and I end up here.
Maybe there is a much more simpler way to check on what number ball stays? Any ideas?

 

   

Yang Li, Administrator
Posted: 04 December 2012 04:01 AM   Total Posts: 80   [ # 10 ]

use dot product is simple, the code is

var v1:Vector3D = boardBody.right;
var v2:Vector3D = sphereBody.position.subtract(boardBody.position);
v2.normalize();
var angle:Number = Math.acos(v1.dotProduct(v2));

angle is radian between sphere and local x axis of boardBody.

 

   

Avatar
TrueSign, Member
Posted: 05 December 2012 11:11 AM   Total Posts: 57   [ # 11 ]

Dot product seems like a good solution.
I have tried that and I found it’s working only partially.
I converted that angle to degrees like that:
var degrees:Number = Math.round(angle * 180 / Math.PI);
And degrees are from 0 to 180 only. I need 360 degrees in order to take correct number from my array.
You can see output here: http://truesign.ie/projects/physicsTest/

 

   

Avatar
TrueSign, Member
Posted: 05 December 2012 05:06 PM   Total Posts: 57   [ # 12 ]

All right. I fixed it finally. Thanks for all your help.

 

   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X