Clarification needed on LookAt matrix calculation in DX9 - c++

I am going trough these 2 methods to calculate the lookat matrix
D3DXMatrixLookAtLH
zaxis = normal(At - Eye)
xaxis = normal(cross(Up, zaxis))
yaxis = cross(zaxis, xaxis)
xaxis.x yaxis.x zaxis.x 0
xaxis.y yaxis.y zaxis.y 0
xaxis.z yaxis.z zaxis.z 0
-dot(xaxis, eye) -dot(yaxis, eye) -dot(zaxis, eye) 1
D3DXMatrixLookAtRH
zaxis = normal(Eye - At)
xaxis = normal(cross(Up, zaxis))
yaxis = cross(zaxis, xaxis)
xaxis.x yaxis.x zaxis.x 0
xaxis.y yaxis.y zaxis.y 0
xaxis.z yaxis.z zaxis.z 0
dot(xaxis, eye) dot(yaxis, eye) dot(zaxis, eye) 1
why is the translation for RH not multiplied by -1?

TL;DR: The Microsoft Doc page for D3DXMatrixLookAtRH is wrong. I've filed a PR to fix it.
In the actual implementation of D3DXMath, it's clear that in both cases the Translation should be -dot(xaxis, eye) -dot(yaxis, eye) -dot(zaxis, eye) for both LH & RH.
The only difference is the zaxis computation.
D3DXMATRIX* WINAPI D3DXMatrixLookAtRH
( D3DXMATRIX *pOut, const D3DXVECTOR3 *pEye, const D3DXVECTOR3 *pAt,
const D3DXVECTOR3 *pUp )
{
D3DXVECTOR3 XAxis, YAxis, ZAxis;
// Compute direction of gaze. (-Z)
D3DXVec3Subtract(&ZAxis, pEye, pAt);
D3DXVec3Normalize(&ZAxis, &ZAxis);
// Compute orthogonal axes from cross product of gaze and pUp vector.
D3DXVec3Cross(&XAxis, pUp, &ZAxis);
D3DXVec3Normalize(&XAxis, &XAxis);
D3DXVec3Cross(&YAxis, &ZAxis, &XAxis);
// Set rotation and translate by pEye
pOut->_11 = XAxis.x;
pOut->_21 = XAxis.y;
pOut->_31 = XAxis.z;
pOut->_41 = -D3DXVec3Dot(&XAxis, pEye);
pOut->_12 = YAxis.x;
pOut->_22 = YAxis.y;
pOut->_32 = YAxis.z;
pOut->_42 = -D3DXVec3Dot(&YAxis, pEye);
pOut->_13 = ZAxis.x;
pOut->_23 = ZAxis.y;
pOut->_33 = ZAxis.z;
pOut->_43 = -D3DXVec3Dot(&ZAxis, pEye);
pOut->_14 = 0.0f;
pOut->_24 = 0.0f;
pOut->_34 = 0.0f;
pOut->_44 = 1.0f;
return pOut;
}
D3DXMATRIX* WINAPI D3DXMatrixLookAtLH
( D3DXMATRIX *pOut, const D3DXVECTOR3 *pEye, const D3DXVECTOR3 *pAt,
const D3DXVECTOR3 *pUp )
{
D3DXVECTOR3 XAxis, YAxis, ZAxis;
// Compute direction of gaze. (+Z)
D3DXVec3Subtract(&ZAxis, pAt, pEye);
D3DXVec3Normalize(&ZAxis, &ZAxis);
// Compute orthogonal axes from cross product of gaze and pUp vector.
D3DXVec3Cross(&XAxis, pUp, &ZAxis);
D3DXVec3Normalize(&XAxis, &XAxis);
D3DXVec3Cross(&YAxis, &ZAxis, &XAxis);
// Set rotation and translate by pEye
pOut->_11 = XAxis.x;
pOut->_21 = XAxis.y;
pOut->_31 = XAxis.z;
pOut->_41 = -D3DXVec3Dot(&XAxis, pEye);
pOut->_12 = YAxis.x;
pOut->_22 = YAxis.y;
pOut->_32 = YAxis.z;
pOut->_42 = -D3DXVec3Dot(&YAxis, pEye);
pOut->_13 = ZAxis.x;
pOut->_23 = ZAxis.y;
pOut->_33 = ZAxis.z;
pOut->_43 = -D3DXVec3Dot(&ZAxis, pEye);
pOut->_14 = 0.0f;
pOut->_24 = 0.0f;
pOut->_34 = 0.0f;
pOut->_44 = 1.0f;
return pOut;
}
Both D3DXMatrixLookAtRH and D3DXMatrixLookAtLH are part of "D3DXMath", the math library included in D3DX9 the D3DX10. These helper libraries are deprecated as is the DirectX SDK itself. The recommendation is to use DirectXMath instead.
If you must use D3DX9 for some reason, note you can avoid all the complicated issues covered on Microsoft Docs mixing the legacy DirectX SDK and modern versions of Visual Studio by just using the Microsoft.DXSDK.D3DX NuGet instead. New projects should move to any of the various replacements. See this blog post for more details.

Related

Ray transformation in a Ray - OBB intersection test

I've implemented an algorithm that tests for a Ray - AABB intersection and it works fine. But when I try to transform Ray to the AABB's local space (making this a Ray - OBB test), I can't get correct results. I've studied several forums and other resources, but still missing something. (Some sources suggesting to apply inverted transformation to the ray origin and its end, and only then calc. direction, other - to apply transformation to origin and direction). Can someone point in the right direction (no pun intended)?
Here goes two functions responsible for the math:
1) Calculating inverses and other things to perform tests
bool Ray::intersectsMesh(const Mesh& mesh, const Transformation& transform) {
float largestNearIntersection = std::numeric_limits<float>::min();
float smallestFarIntersection = std::numeric_limits<float>::max();
glm::mat4 modelTransformMatrix = transform.modelMatrix();
Box boundingBox = mesh.boundingBox();
glm::mat4 inverse = glm::inverse(transform.modelMatrix());
glm::vec4 newOrigin = inverse * glm::vec4(mOrigin, 1.0);
newOrigin /= newOrigin.w;
mOrigin = newOrigin;
mDirection = glm::normalize(inverse * glm::vec4(mDirection, 0.0));
glm::vec3 xAxis = glm::vec3(glm::column(modelTransformMatrix, 0));
glm::vec3 yAxis = glm::vec3(glm::column(modelTransformMatrix, 1));
glm::vec3 zAxis = glm::vec3(glm::column(modelTransformMatrix, 2));
glm::vec3 OBBTranslation = glm::vec3(glm::column(modelTransformMatrix, 3));
printf("trans x %f y %f z %f\n", OBBTranslation.x, OBBTranslation.y, OBBTranslation.z);
glm::vec3 delta = OBBTranslation - mOrigin;
bool earlyFalseReturn = false;
calculateIntersectionDistances(xAxis, delta, boundingBox.min.x, boundingBox.max.x, &largestNearIntersection, &smallestFarIntersection, &earlyFalseReturn);
if (smallestFarIntersection < largestNearIntersection || earlyFalseReturn) { return false; }
calculateIntersectionDistances(yAxis, delta, boundingBox.min.y, boundingBox.max.y, &largestNearIntersection, &smallestFarIntersection, &earlyFalseReturn);
if (smallestFarIntersection < largestNearIntersection || earlyFalseReturn) { return false; }
calculateIntersectionDistances(zAxis, delta, boundingBox.min.z, boundingBox.max.z, &largestNearIntersection, &smallestFarIntersection, &earlyFalseReturn);
if (smallestFarIntersection < largestNearIntersection || earlyFalseReturn) { return false; }
return true;
}
2) Helper function (probably not needed here as its relates only to AABB tests and works fine)
void Ray::calculateIntersectionDistances(const glm::vec3& axis,
const glm::vec3& delta,
float minPointOnAxis,
float maxPointOnAxis,
float *largestNearIntersection,
float *smallestFarIntersection,
bool *earlyFalseRerutn)
{
float divident = glm::dot(axis, delta);
float denominator = glm::dot(mDirection, axis);
if (fabs(denominator) > 0.001f) {
float t1 = (divident + minPointOnAxis) / denominator;
float t2 = (divident + maxPointOnAxis) / denominator;
if (t1 > t2) { std::swap(t1, t2); }
*smallestFarIntersection = std::min(t2, *smallestFarIntersection);
*largestNearIntersection = std::max(t1, *largestNearIntersection);
} else if (-divident + minPointOnAxis > 0.0 || -divident + maxPointOnAxis < 0.0) {
*earlyFalseRerutn = true;
}
}
As it turned out, the ray's world -> model transformation was correct. The bug was in the intersection test. I had to completely replace the intersection code, because I wasn't able to identify the bug in the old code, unfortunately.
Ray transformation code:
glm::mat4 inverse = glm::inverse(transform.modelMatrix());
glm::vec4 start = inverse * glm::vec4(mOrigin, 1.0);
glm::vec4 direction = inverse * glm::vec4(mDirection, 0.0);
direction = glm::normalize(direction);
And the Ray - AABB test was stolen from here

Ray casting in rotating fan configuration produces point cloud with curvature, how to eliminate curvature?

I'm attempting to perform an intersection test using ray casting (not sure if correct term so please forgive me if not) and am outputting the intersections as a point cloud, and the point cloud shows curvature (on the Z-axis only, the point cloud is completely flat on the Y axis, and the horizontal axis in this image is the X axis):
I borrowed concepts from the Scratchapixel site, specifically http://scratchapixel.com/lessons/3d-basic-rendering/minimal-ray-tracer-rendering-simple-shapes/ray-box-intersection.
Essentially, I am generating 16 rays, all with the same origin vector. The direction vectors start at +15 degrees on the YZ plane, and continue in increments of -2 degrees down to -15. I have an axis aligned bounding box that I am testing intersection with. I use a rotation transform to rotate the 16 rays CCW around the Z axis. I am performing the intersection test for all 16 rays each 0.1 degrees, and if it returns true, I add the point to the point cloud.
Here's my intersection code:
bool test_intersect(Box b, Ray r, Vec3f& intersect_point)
{
float txmin = 0.0f, txmax = 0.0f, tymin = 0.0f, tymax = 0.0f, tzmin = 0.0f, tzmax = 0.0f;
float t_min = 0.0f, t_max = 0.0f, t = 0.0f;
// Determine inverse direction of ray to alleviate 0 = -0 issues
Vec3f inverse_direction(1 / r.direction.x, 1 / r.direction.y, 1 / r.direction.z);
// Solving box_min/box_max0 = O + Dt
txmin = (b.box_min.x - r.origin.x) * inverse_direction.x;
txmax = (b.box_max.x - r.origin.x) * inverse_direction.x;
tymin = (b.box_min.y - r.origin.y) * inverse_direction.y;
tymax = (b.box_max.y - r.origin.y) * inverse_direction.y;
tzmin = (b.box_min.z - r.origin.z) * inverse_direction.z;
tzmax = (b.box_max.z - r.origin.z) * inverse_direction.z;
// Depending on direction of ray tmin may > tmax, so we may need to swap
if (txmin > txmax) std::swap(txmin, txmax);
if (tymin > tymax) std::swap(tymin, tymax);
if (tzmin > tzmax) std::swap(tzmin, tzmax);
t_min = txmin;
t_max = txmax;
// If t-value of a min is greater than t-value of max,
// we missed the object in that plane.
if ((t_min > tymax) || (tymin > t_max))
return false;
if (tymin > t_min)
t_min = tymin;
if (tymax < t_max)
t_max = tymax;
if ((t_min > tzmax) || (tzmin > t_max))
return false;
if (tzmin > t_min)
t_min = tzmin;
if (tzmax < t_max)
t_max = tzmax;
if (t_min > 0)
t = t_min;
else
if (t_max > 0)
t = t_max;
else
return false;
intersect_point.x = r.origin.x + r.direction.x * t;
intersect_point.y = r.origin.y + r.direction.y * t;
intersect_point.z = r.origin.z + r.direction.z * t;
return true;
}
And my rotation:
// Rotation around z axis, for rotating array and checking beam intersections
void transform_rotate_z(Vec3f& in_vector, float angle)
{
float radians = angle * (M_PI / 180);
float result_x = cos(radians) * in_vector.x + -sin(radians) * in_vector.y;
float result_y = sin(radians) * in_vector.x + cos(radians) * in_vector.y;
in_vector.x = result_x;
in_vector.y = result_y;
}
I have racked my brain for quite a while but I can't seem to determine how I can prevent this curvature, I'm sure I'm overlooking something simple. I'd be grateful for any help you can provide.

Camera matrix invalid when aligned with up vector

I'm currently implementing cameras on my engine and I'm having an issue when the camera is looking from top to the floor (example, eye position 0.,0.,50. and target is 0.,0.,0.) my up vector is 0.,0.,1..
Then when I do the maths, the crossproduct of position and up gives 0.,0.,0. and then the view is screwed and nothing is rendered. If I move the camera, everything works as expected.
How can I solve this?
if (node==NULL || target==NULL) return;
node->Update();
eye=node->GetWorldMatrix()*GRPVECTOR(0.0,0.0,0.0); //converts from matrix to vector my vector transformation
target->Update();
obj=target->GetWorldMatrix()*GRPVECTOR(0.0,0.0,0.0);
GRPVECTOR ev;
GRPVECTOR z;
GRPVECTOR x_tmp;
GRPVECTOR x;
GRPVECTOR y;
ev = eye - obj;
ev.Normalize();
z=ev;
x_tmp.CrossProduct(&up,&z);
if (x_tmp.GetLengthf()==0.0f)
return; //my view is screwed, I return
x_tmp.Normalize();
x=x_tmp;
y.CrossProduct(&z,&x);
this->viewmatrix.matrix[0][0] = x.vector[0];
this->viewmatrix.matrix[0][1] = y.vector[0];
this->viewmatrix.matrix[0][2] = z.vector[0];
this->viewmatrix.matrix[0][3] = 0.0f;
this->viewmatrix.matrix[1][0] = x.vector[1];
this->viewmatrix.matrix[1][1] = y.vector[1];
this->viewmatrix.matrix[1][2] = z.vector[1];
this->viewmatrix.matrix[1][3] = 0.0f;
this->viewmatrix.matrix[2][0] = x.vector[2];
this->viewmatrix.matrix[2][1] = y.vector[2];
this->viewmatrix.matrix[2][2] = z.vector[2];
this->viewmatrix.matrix[2][3] = 0.0f;
this->viewmatrix.matrix[3][0] = -x.vector[0] * eye.vector[0] + -x.vector[1] * eye.vector[1] + -x.vector[2] * eye.vector[2];
this->viewmatrix.matrix[3][1] = -y.vector[0] * eye.vector[0] + -y.vector[1] * eye.vector[1] + -y.vector[2] * eye.vector[2];
this->viewmatrix.matrix[3][2] = -z.vector[0] * eye.vector[0] + -z.vector[1] * eye.vector[1] + -z.vector[2] * eye.vector[2];
this->viewmatrix.matrix[3][3] = 1.0f;
GRPMATRIX Translate;
Translate.BuildTranslationMatrix(-obj.vector[0],-obj.vector[1],-obj.vector[2]);
this->viewmatrix.GetMulplicationMatrix(&this->viewmatrix,&Translate);

Bullet vehicle wheels fall behind and wrong chassis pitch direction

I have created a bullet vehicle with a attached turret at the top like this:
gEngineForce = 0.f;
gBreakingFrontForce = 0.f;
gBreakingBackForce = 0.f;
maxEngineForce = 20000.f;
minEngineForce = -2000.f;
maxBreakingFrontForce = 4000.f;
maxBreakingBackForce = 600.f;
gVehicleSteering = 0.f;
steeringIncrement = 0.002f;
steeringClamp = 0.6f;
wheelRadius = 0.5f;
wheelWidth = 0.4f;
wheelFriction = 50;
suspensionStiffness = 10.f;
suspensionDamping = 1.3f;
suspensionCompression = 4.4f;
rollInfluence = 0.1f;//1.0f
btScalar suspensionRestLength(0.6);
btVector3 wheelDirectionCS0(0, -1, 0);
btVector3 wheelAxleCS(-1, 0, 0);
btTransform tr;
tr.setIdentity();
chassisShape = new btBoxShape(btVector3(1.f, 0.5f, 2.f));
bulletCollisionShapes.push_back(chassisShape);
compound = new btCompoundShape();
bulletCollisionShapes.push_back(compound);
btTransform chassisTrans;
chassisTrans.setIdentity();
//localTrans effectively shifts the center of mass with respect to the chassis
chassisTrans.setOrigin(btVector3(0, 1.3, 0));
compound->addChildShape(chassisTrans, chassisShape);
tr.setOrigin(btVector3(0, 0.f, 0));
//m_carChassis = CreateRigidBody(2000, tr, compound);
//m_carChassis->setDamping(0.2,0.2);
m_wheelShape = new btCylinderShapeX(btVector3(wheelWidth, wheelRadius, wheelRadius));
m_carChassis = CreateRigidBody(2000, tr, compound);
// create turret
turretShape = new btBoxShape(btVector3(0.4f, 0.2f, 0.8f));
bulletCollisionShapes.push_back(turretShape);
btTransform turretTrans;
turretTrans.setIdentity();
turretTrans.setOrigin(btVector3(0.0f, 0.7f, 0.0f));
turretBody = CreateRigidBody(1, turretTrans, turretShape);
// add some data to build constraint frames
btVector3 axisA(0.f, 1.f, 0.f);
btVector3 axisB(0.f, 0.f, 0.f);
btVector3 pivotA(0.f, 1.f, 0.f);
btVector3 pivotB(0.f, 0.f, 0.f);
hinge = new btHingeConstraint(*m_carChassis, *turretBody, pivotA, pivotB, axisA, axisB);
//hinge->setLimit(-SIMD_HALF_PI * 0.5f, SIMD_HALF_PI * 0.5f);
hinge->enableAngularMotor(true, 0, 1);
// add constraint to world
bt_dynamicsWorld->addConstraint(hinge, true);
{
btTransform something;
something.setIdentity();
something.setOrigin(btVector3(0, 10, 0));
m_carChassis->setWorldTransform(something);
m_vehicleRayCaster = new btDefaultVehicleRaycaster(bt_dynamicsWorld);
m_vehicle = new btRaycastVehicle(m_tuning, m_carChassis, m_vehicleRayCaster);
m_carChassis->setActivationState(DISABLE_DEACTIVATION);
bt_dynamicsWorld->addVehicle(m_vehicle);
float connectionHeight = 1.2f;
//choose coordinate system
m_vehicle->setCoordinateSystem(rightIndex, upIndex, forwardIndex);
bool isFrontWheel = true;
btVector3 connectionPointCS0(1 - (-0.8*wheelWidth), connectionHeight, 3 * 1 - wheelRadius);
m_vehicle->addWheel(connectionPointCS0, wheelDirectionCS0, wheelAxleCS, suspensionRestLength, wheelRadius, m_tuning, isFrontWheel);
connectionPointCS0 = btVector3(-1 + (-0.8*wheelWidth), connectionHeight, 3 * 1 - wheelRadius);
m_vehicle->addWheel(connectionPointCS0, wheelDirectionCS0, wheelAxleCS, suspensionRestLength, wheelRadius, m_tuning, isFrontWheel);
isFrontWheel = false;
connectionPointCS0 = btVector3(-1 + (-0.8*wheelWidth), connectionHeight, -3 * 1 + wheelRadius);
m_vehicle->addWheel(connectionPointCS0, wheelDirectionCS0, wheelAxleCS, suspensionRestLength, wheelRadius, m_tuning, isFrontWheel);
connectionPointCS0 = btVector3(1 - (-0.8*wheelWidth), connectionHeight, -3 * 1 + wheelRadius);
m_vehicle->addWheel(connectionPointCS0, wheelDirectionCS0, wheelAxleCS, suspensionRestLength, wheelRadius, m_tuning, isFrontWheel);
for (int i = 0; i < m_vehicle->getNumWheels(); i++)
{
btWheelInfo& wheel = m_vehicle->getWheelInfo(i);
wheel.m_suspensionStiffness = suspensionStiffness;
wheel.m_wheelsDampingRelaxation = suspensionDamping;
wheel.m_wheelsDampingCompression = suspensionCompression;
wheel.m_frictionSlip = wheelFriction;
wheel.m_rollInfluence = rollInfluence;
}
}
int wheelIndex = 2;
m_vehicle->applyEngineForce(gEngineForce, wheelIndex);
m_vehicle->setBrake(gBreakingBackForce, wheelIndex);
wheelIndex = 3;
m_vehicle->applyEngineForce(gEngineForce, wheelIndex);
m_vehicle->setBrake(gBreakingBackForce, wheelIndex);
wheelIndex = 0;
m_vehicle->setSteeringValue(gVehicleSteering, wheelIndex);
m_vehicle->setBrake(gBreakingFrontForce, wheelIndex);
wheelIndex = 1;
m_vehicle->setSteeringValue(gVehicleSteering, wheelIndex);
m_vehicle->setBrake(gBreakingFrontForce, wheelIndex);
This is how I render the vehicle:
// render wheels
btScalar mwheel[16];
for (int i = 0; i<m_vehicle->getNumWheels(); i++){
//synchronize the wheels with the (interpolated) chassis worldtransform
m_vehicle->updateWheelTransform(i, true);
//draw wheels
m_vehicle->getWheelInfo(i).m_worldTransform.getOpenGLMatrix(mwheel);
RenderWheel(m_wheelShape, mwheel);
}
// render car chassis
btScalar mchassis[16];
m_vehicle->getChassisWorldTransform().getOpenGLMatrix(mchassis);
RenderBox(chassisShape, mchassis);
// render turret
btScalar mturret[16];
// get chassis and turret transforms
btTransform chassisTransform = m_vehicle->getChassisWorldTransform();
//btTransform turretTransform = compound->getChildTransform(1);
btTransform turretTransform = turretBody->getWorldTransform();
// multiply transforms to get updated turret transform
//turretTransform *= chassisTransform;
turretTransform.getOpenGLMatrix(mturret);
RenderBox(turretShape, mturret);
Using the arrow keys I apply break or acceleration forces like this:
bullet.gEngineForce = bullet.maxEngineForce;
bullet.gBreakingFrontForce = 0.f;
bullet.gBreakingBackForce = 0.f;
etc.
The camera is attached to the turret on top of the car, therefore attached to the car itself.
The issue is that when the car starts moving and as it gain speed, the wheels seem to fall behind and the chassis going forward. I would like make the wheels and the chassis more tight, but playing around with the car suspension settings did not help.
Here is a video demonstrating this behaviour: click
I have also noticed another strange behaviour related to the way the car pitches when moving, breaking and turning.
Increasing the gravity accentuates this behaviour. when I accelerate, the chassis pitches forward and when I brake it goes backwards. This is obviously wrong as it should be the other way around. Same happens when turning left, the car pitches left instead of right, and the other way around.
Here is another video demonstrating this behaviour: click
i had this kind of problem. it turned out that wheels were rendered using transformation not from the same frame as chassis. i.e. from frame n-1 while chassis used frame n.
things werent apparent bcause wheel meshes were child nodes of chassis node, as it was how it was implemented by me in rendering engine, while in bullet physics, wheel coordinates are global, the same way chassis is.
but that wasnt all, when converting wheel coords from global to local vehicle space, there was accuracy loss that, still caused problems. it was fixed by making wheel meshes as global nodes.

Joint on the edge of the circle

The green square is the box2d ground.
The bigger circle is connected to the ground by revolute joint, and can be rotated.
All the circles are b2_dynamicBody
I want to joint the smaller circles on the edge or border of the bigger circle as shown below.
Please tell me how can i achieve it and what kind of joint i have to use?
Also when i rotate big circle the small circle should stick at its place.
Go through this code....
// create joint between hook big circle
wheelSprite = [[CCSprite alloc] initWithFile:#"heroWheel.png"];
wheelSprite.visible = FALSE;
wheelSprite.scale = 1.0*hero_size_factor;
wheelSprite.rotation = 0.0;
wheelSprite.anchorPoint = CGPointMake(0.5,0.5);
[layer addChild:wheelSprite z:5];
ballBodyDef.userData = wheelSprite;
//create hook between big circle
hook = world->CreateBody(&ballBodyDef);
b2PolygonShape hookShape;
hookShape.SetAsBox(0.2,0.1);
b2FixtureDef hookDef;
hookDef.shape=&hookShape;
hookDef.density=0.5f*hero_size_factor;
hookDef.friction = 0.0f;
hookDef.restitution = 0.0f;
hookDef.filter.groupIndex=heroGroupIndex;
hook->CreateFixture(&hookDef);
//create circle shape fixture
b2CircleShape wheel1,wheel2,wheel3,wheel4;
float wheelRadius = hero_width/4.0f;
//Create fixture with above shape
b2FixtureDef ballShapeDef1,ballShapeDef2,ballShapeDef3,ballShapeDef4;
wheel1.m_p = b2Vec2(wheelRadius, wheelRadius);
wheel1.m_radius = wheelRadius;
ballShapeDef1.shape = &wheel1;
ballShapeDef1.density = 0.0f;
ballShapeDef1.friction = 0.0f;
ballShapeDef1.restitution = 0.0f;
ballShapeDef1.filter.groupIndex=heroGroupIndex;
hook->CreateFixture(&ballShapeDef1);
wheel2.m_radius = wheelRadius;
wheel2.m_p = b2Vec2(-wheelRadius, -wheelRadius);
ballShapeDef2.shape = &wheel2;
ballShapeDef2.density = 0.0f;
ballShapeDef2.friction = 0.0f;
ballShapeDef2.restitution = 0.0f;
ballShapeDef2.filter.groupIndex=heroGroupIndex;
hook->CreateFixture(&ballShapeDef2);
wheel3.m_radius = wheelRadius;
wheel3.m_p = b2Vec2(wheelRadius,-wheelRadius);
ballShapeDef3.shape = &wheel3;
ballShapeDef3.density = 0.0f;
ballShapeDef3.friction = 0.0f;
ballShapeDef3.restitution = 0.0f;
ballShapeDef3.filter.groupIndex=heroGroupIndex;
hook->CreateFixture(&ballShapeDef3);
wheel4.m_radius = wheelRadius;
wheel4.m_p = b2Vec2(-wheelRadius,wheelRadius);
ballShapeDef4.shape = &wheel4;
ballShapeDef4.density = 0.0f;
ballShapeDef4.friction = 0.0f;
ballShapeDef4.restitution = 0.0f;
ballShapeDef4.filter.groupIndex=heroGroupIndex;
hook->CreateFixture(&ballShapeDef4);
//Create Revolute Joints between hook and big circle
b2RevoluteJointDef revoluteJointDef;
revoluteJointDef.bodyA = hook;
revoluteJointDef.bodyB = Leg;
revoluteJointDef.collideConnected = false;
revoluteJointDef.localAnchorA.Set(0.0,0.0);
revoluteJointDef.localAnchorB.Set(0.0,-(hero_height - 0.1));
revoluteJointDef.referenceAngle = 0;
revoluteJointDef.maxMotorTorque = 5.0*hero_size_factor;
Hero_Motor = (b2RevoluteJoint*)world->CreateJoint(&revoluteJointDef);