Jump to content

  • Log In with Google      Sign In   
  • Create Account


Xoliul

Member Since 20 Feb 2008
Offline Last Active May 24 2012 12:31 PM
-----

Topics I've Started

Compiled Shader looks different

24 May 2012 - 06:58 AM

I've written a procedural noise shader. It's pretty heavy but it only serves to Render-To-Texture so that's fine.
One big problem I have is that the compile time is pretty insane, so I'm trying to precompile it using FXC.exe. I have to use the June 2010 DX SDK because it's not an SM4.0 shader (my application, 3DS Max, is still D3D9).

Now the problem with the assembly code that FXC generates, is that it doesn't work exactly the same as the uncompiled code. The values the noise functions generate are in a very different range, resulting in pretty much nothing visible. If my application compiles it with its own compiler, it works fine...

This is a bit of a long shot, but would anyone know what is going wrong?

Tokamak car physics

20 February 2008 - 07:47 AM

Okay, I'm new here, pretty serious question to begin with. We're starting on a game project for school, which will be utilizing Tokamak physics? You'll be driving a car, so I need to do the car physics. I'll have Tokamak handle collision and integration of forces over time, and do the tire and suspension code myself, starting with the car example code that is available on their site.
Now thing is, I want to fully understand this code before I start using and modifying it myself, yet I have some trouble with it.

Here's what I have so far (posting all of the car control code so it's understandable):

void CSampleCar::CarController(neRigidBodyController * controller)
{
	neT3 body2World = carRigidBody->GetTransform();

	carRigidBody->BeginIterateSensor();

	neSensor * sn;

	neV3 force, torque;

	force.SetZero();

	torque.SetZero();

	s32 i = 0;

	while (sn = carRigidBody->GetNextSensor())
	{
		f32 k = 6.0f; //spring constant

		f32 u = 0.8f; //damping constant

		if (i == 2 || i == 3)
		{
			k = 10.0f;
		}

		// add spring force

		f32 depth = sn->GetDetectDepth();

		//gw.car.suspensionLength[i] = 1.0f - depth;
		suspensionLength[i] = 1.0f - depth;

		if (depth == 0.0f)
		{
			i++;
			continue;
		}
		//if (depth > 0.7f)
		//	depth = 0.7f;
		
		neV3 groundNormal = sn->GetDetectNormal();

		neV3 lineNormal = body2World.rot * sn->GetLineUnitVector();

		neV3 linePos = body2World * sn->GetLinePos();

		f32 dot = lineNormal.Dot(groundNormal) * -1.0f; //apparently unused ?

		//if (dot <= 0.7f)
		//	continue;


		neV3 f = depth * lineNormal * -k ;//* dot; //get spring push force: force along normal, strength from spring compression (inverse)

		force += f;//add spring force to total wheel force vector

		neV3 r = linePos - carRigidBody->GetPos();//get normalised wheel offset

		torque += r.Cross(f);//add normal of spring force and normalised wheel offset to torque vector -> torque vector serves for 

		// add damping force
		
		//GetVelocityAtPoint most probably requires a relative value from the rigid body's center
		f32 speed = carRigidBody->GetVelocityAtPoint(r).Dot(lineNormal); //dot product of linenormal and velocity at relative wheel offset for scalar speed value
		//speed is the car bodies speed along the sensor line's normal vector

		f = -speed * lineNormal * u; //inverse speed along sensor, dampened by dampening constant, along sensor line's normal.

		force += f; //add dampening force to suspension force

		torque += r.Cross(f);//apply dampening torque

		// add friction force

		neV3 vel = carRigidBody->GetVelocityAtPoint( sn->GetDetectContactPoint() - carRigidBody->GetPos() ); //get velocity at wheel/ground contactpoint

		vel.RemoveComponent(groundNormal);

		//RemoveComponent function code, copied from library source
		/*	RemoveComponent	(const neV3& V)
		{
			f32 dot = (*this).Dot(V);

			(*this) = (*this) - V * dot;
		}
		*/

		if (i == 0 || i == 1)
		{
			//steering

			vel.RemoveComponent(steerDir);
		}
		else
		{
			vel.RemoveComponent(body2World.rot[0]); //rear wheel always parallel to car body
		}


		f = vel;

		f.Normalize();

		f *= -2.0f;

		if (i == 2 || i ==3)
		{
			f *= (1.0f - slide);
		}
		f[1] = 0.0f;
		
		force += f;

		r = sn->GetDetectContactPoint() - carRigidBody->GetPos();

		torque += r.Cross(f);

		// driving force

		if (i == 2 || i == 3) // rear wheel
		{
			f = body2World.rot[0];

			f *= accel;

			force += f;

			torque += r.Cross(f);
		}
/*
		gw.car.displayLines[i][0] = linePos;

		gw.car.displayLines[i][1] = sn->GetDetectContactPoint();
*/
		i++;
	}

	// drag
	f32 dragConstant = 0.5f;

	neV3 vel = carRigidBody->GetVelocity();

	f32 dot = vel.Dot(body2World.rot[0]);

	neV3 drag = dot * body2World.rot[0] * -dragConstant;

	force += drag;

	controller->SetControllerForce(force);

	controller->SetControllerTorque(torque);
}



Where I'm running stuck in trying to understand, is as soon as they start to use the neV3.RemoveComponent() function. I don't understand what excatly the result of this function is supposed to be, and I don't understand how these functions will create the friction forces. Also, why do they normalize the velocity vector afterwards ?

I really want to understand the friction and grip part here, as this is where the demo is lacking most of all: the friction model will need a lot more elaboration in our project, so naturally I want to fully understand it before I start changing it.

Hope somebody can help me out here, as I really don't have anybody I can ask this.

[Edited by - Xoliul on February 20, 2008 2:18:12 PM]

PARTNERS