NewtonCollision* dCollisionConeNodeInfo::CreateNewtonCollision (NewtonWorld* const world, dScene* const scene, dScene::dTreeNode* const myNode) const
{
	dAssert (IsType (dCollisionConeNodeInfo::GetRttiType()));

	// get the collision node	
	int collisionID = GetShapeId ();
	const dMatrix& offsetMatrix = GetTransform ();
	
	// create a newton collision shape from the node.
	return NewtonCreateCone(world, m_radius, m_height, collisionID, &offsetMatrix[0][0]);
}
static unsigned RayPrefilter (const NewtonBody* const body, const NewtonCollision* const collision, void* const userData)
{
	// if the collision has a parent, the this can be it si a sub shape of a compound collision 
	const NewtonCollision* const parent = NewtonCollisionGetParentInstance(collision);
	if (parent) {
		// you can use this to filter sub collision shapes.  
		dAssert (NewtonCollisionGetSubCollisionHandle (collision));
	}

	return 1;
}
dScriptCompiler::dUserVariable dScriptCompiler::FunctionAddParameterNode (const dUserVariable& parameter)
{
	dUserVariable returnNode;

	dDAGParameterNode* const parameterNode = (dDAGParameterNode*)parameter.m_node;
	dAssert (parameterNode->GetTypeId() == dDAGParameterNode::GetRttiType());

	dDAGFunctionNode* const function = GetCurrentClass()->GetCurrentFunction();
	function->AddParameter(parameterNode);
	return returnNode;
}
dScriptCompiler::dUserVariable dScriptCompiler::NewExpressionOperatorNew (const dString& typeName, const dUserVariable& dimension)
{
	dUserVariable returnNode;

	dDAGDimensionNode* const dimensionNode = (dDAGDimensionNode*) dimension.m_node;
	dAssert (dimensionNode->IsType (dDAGDimensionNode::GetRttiType()));
	dDAGExpressionNodeNew* const node = new dDAGExpressionNodeNew (m_allNodes, typeName.GetStr(), dimensionNode);

	returnNode.m_node = node;
	return returnNode;
}
dDAGFunctionStatementCase::dDAGFunctionStatementCase(dList<dDAG*>& allNodes, const char* const nameID, dDAGFunctionStatement* const childStatement)
	:dDAGFunctionStatement(allNodes)
	,m_nameId(nameID)
	,m_statementList()
{
	for (dDAGFunctionStatement* node = childStatement; node; node = (dDAGFunctionStatement*) node->m_next) {
		m_statementList.Append(node);
		dAssert (0);
//		node->AddRef();
	}
}
bool dCILInstrMove::ApplyCopyPropagation (dCILInstrMove* const moveInst) 
{ 
	bool ret = false;
	if (moveInst->m_arg0.m_label == m_arg1.m_label) {
		ret = true;
		m_arg1.m_label = moveInst->m_arg1.m_label;
	}
	
	dAssert(ret);
	return ret;
}
	dListNode* Find (dCRCTYPE nameCRC) const
	{
		for (dListNode* node = GetFirst(); node; node = node->GetNext()) {
			if (node->GetInfo().m_nameCRC == nameCRC) {
				return node;
			}
		}

		dAssert (0);
		return NULL;
	}
void dCILInstrPhy::Serialize(char* const textOut) const
{
	sprintf(textOut, "\t%s %s = phi (", m_arg0.GetTypeName().GetStr(), m_arg0.m_label.GetStr());
	for (dList<dArgPair>::dListNode* node = m_sources.GetFirst(); node; node = node->GetNext()) {
		char tmp[1024]; 

		dArgPair& pair = node->GetInfo();
		dArg* const arg = pair.m_intructionNode ? pair.m_intructionNode->GetInfo()->GetGeneratedVariable() : &pair.m_arg;
		dAssert (arg);
		dCILInstrLabel* const block = pair.m_block->m_begin->GetInfo()->GetAsLabel();
		dAssert(block);
		if (node->GetNext()) {
			sprintf(tmp, "[%s %s, %s], ", arg->GetTypeName().GetStr(), arg->m_label.GetStr(), block->GetArg0().m_label.GetStr());
		} else {
			sprintf(tmp, "[%s %s, %s]", arg->GetTypeName().GetStr(), arg->m_label.GetStr(), block->GetArg0().m_label.GetStr());
		}
		strcat(textOut, tmp);
	}
	strcat(textOut, ")\n");
}
void dCILInstrStore::AddUsedVariable (dInstructionVariableDictionary& dictionary) const 
{
	dAssert(0);
/*
	dInstructionVariableDictionary::dTreeNode* const node0 = dictionary.Insert(m_arg0.m_label);
	node0->GetInfo().Append(m_myNode);

	dInstructionVariableDictionary::dTreeNode* const node1 = dictionary.Insert(m_arg1.m_label);
	node1->GetInfo().Append(m_myNode);
*/
}
dScriptCompiler::dUserVariable dScriptCompiler::NewIFStatement(const dUserVariable& expression, const dUserVariable& thenExpression, const dUserVariable& elseExpression)
{
	dUserVariable returnNode;

	dDAGExpressionNode* const expresionNode = (dDAGExpressionNode*) expression.m_node;
	dAssert (expresionNode->IsType(dDAGExpressionNode::GetRttiType()));

	dDAGFunctionStatement* const thenStmt = (dDAGFunctionStatement*) thenExpression.m_node;

	dDAGFunctionStatement* elseStmt = NULL;
	if (elseExpression.m_node) {
		elseStmt = (dDAGFunctionStatement*) elseExpression.m_node;
	}

	dDAGFunctionStatementIF* const stmt = new dDAGFunctionStatementIF(m_allNodes, expresionNode, thenStmt, elseStmt);

	dAssert (thenStmt->IsType(dDAGFunctionStatement::GetRttiType()) || thenStmt->IsType(dDAGExpressionNode::GetRttiType()));
	returnNode.m_node = stmt;
	return returnNode;
}
void dMeshNodeInfo::DrawWireFrame(dSceneRender* const render, dScene* const scene, dScene::dTreeNode* const myNode) const
{
	dAssert (myNode == scene->Find(GetUniqueID()));
	dAssert (scene->GetInfoFromNode(myNode) == this);


	int displayList = render->GetCachedWireframeDisplayList(m_mesh);
	dAssert (displayList > 0);
	
	render->PushMatrix(&m_matrix[0][0]);
	if (GetEditorFlags() & m_selected) {
		dVector color (render->GetColor());
		render->SetColor(dVector (1.0f, 1.0f, 0.0f, 0.0f));
		render->DrawDisplayList(displayList);
		render->SetColor(color);
	} else {
		render->DrawDisplayList(displayList);
	}
	render->PopMatrix();
}
void dBasicBlocksGraph::CalculateSuccessorsAndPredecessors ()
{
	m_mark += 1;
	dList<dBasicBlock*> stack;
	stack.Append(&GetFirst()->GetInfo());

	while (stack.GetCount()) {
		dBasicBlock* const block = stack.GetLast()->GetInfo();

		stack.Remove(stack.GetLast()->GetInfo());
		if (block->m_mark < m_mark) {

			block->m_mark = m_mark;
			//m_traversalBlocksOrder.Addtop(block);
//block->Trace();

			dCILInstr* const instruction = block->m_end->GetInfo();
			dAssert(instruction->IsBasicBlockEnd());
			if (instruction->GetAsIF()) {
				dCILInstrConditional* const ifInstr = instruction->GetAsIF();

				dAssert (ifInstr->GetTrueTarget());
				dAssert (ifInstr->GetFalseTarget());

				dCILInstrLabel* const target0 = ifInstr->GetTrueTarget()->GetInfo()->GetAsLabel();
				dCILInstrLabel* const target1 = ifInstr->GetFalseTarget()->GetInfo()->GetAsLabel();

				dBasicBlock* const block0 = target0->m_basicBlock;
				dAssert (block0);
				block->m_successors.Append (block0);
				block0->m_predecessors.Append(block);
				stack.Append (block0);

				dBasicBlock* const block1 = target1->m_basicBlock;
				dAssert(block1);
				block->m_successors.Append(block1);
				block1->m_predecessors.Append(block);
				stack.Append(block1);

			} else if (instruction->GetAsGoto()) {
				dCILInstrGoto* const gotoInst = instruction->GetAsGoto();

				dAssert(gotoInst->GetTarget());
				dCILInstrLabel* const target = gotoInst->GetTarget()->GetInfo()->GetAsLabel();
				dBasicBlock* const block0 = target->m_basicBlock;

				dAssert(block0);
				block->m_successors.Append(block0);
				block0->m_predecessors.Append(block);
				stack.Append(block0);
			}
		}
	}

	DeleteUnreachedBlocks();
}
dNewtonLuaCompiler::dUserVariable dNewtonLuaCompiler::EmitAssigmentStatement(const dUserVariable& nameList, const dUserVariable& expresionList)
{
	//dList<dCIL::dListNode*>::dListNode* nameListNode = nameList.m_nodeList.GetFirst();
	dList<dString>::dListNode* nameListNode = nameList.m_tokenList.GetFirst();
	dList<dCIL::dListNode*>::dListNode* expressionListNode = expresionList.m_nodeList.GetFirst();
	dAssert(nameList.m_tokenList.GetCount() >= 1);
	dAssert(expresionList.m_nodeList.GetCount() >= 1);
	int count = dMin (nameList.m_tokenList.GetCount(), expresionList.m_nodeList.GetCount());
	for (int i = 0; i < count; i ++) {
		//dCILSingleArgInstr* const dst = nameListNode->GetInfo(); 
		const dString& dstName = nameListNode->GetInfo();

/*
		if (dest->GetAsLocal()) {
			dCILInstrLocal* const dstIntruction = dest->GetAsLocal();
			const dCILInstr::dArg& argName = dstIntruction->GetArg0();
			for (dList<dCILInstrLocal*>::dListNode* node = m_currentClosure->m_localVariables.GetFirst(); node; node = node->GetNext()) {
				dCILInstrLocal* const intruction = node->GetInfo()->GetAsLocal();
				dAssert(intruction);
				if (argName.m_label == intruction->GetArg0().m_label) {
					destArg = argName;
					break;
				}
			}
		}
*/


		dCILSingleArgInstr* const src = expressionListNode->GetInfo()->GetInfo()->GetAsSingleArg(); 
		dAssert(src);
		//dAssert(dst);
		//const dCILInstr::dArg& dstArg = dst->GetArg0();
		const dCILInstr::dArg& srcArg = src->GetArg0();
		dCILInstrMove* const move = new dCILInstrMove(*m_currentClosure, dstName, srcArg.GetType(), srcArg.m_label, srcArg.GetType());
		TRACE_INSTRUCTION(move);

		nameListNode = nameListNode->GetNext();
		expressionListNode = expressionListNode->GetNext();
	}
	return dUserVariable();
}
dScriptCompiler::dUserVariable dScriptCompiler::NewVariableToCurrentBlock (const dString& modifiers, const dUserVariable& type, const dString& name)
{
	dUserVariable variableName(NewVariableStatement (name, modifiers));

	dDAGParameterNode* const variableNameNode = (dDAGParameterNode*)variableName.m_node;
	dAssert (variableNameNode->IsType(dDAGParameterNode::GetRttiType()));

	dDAGTypeNode* const typeNode = (dDAGTypeNode*)type.m_node;
	dAssert (typeNode->GetTypeId() == dDAGTypeNode::GetRttiType());
	variableNameNode->SetType(typeNode);

	dAssert (m_scopeStack.GetCount());
	dDAGScopeBlockNode* const block = GetCurrentScope();
	block->AddStatement(variableNameNode);

	dUserVariable returnNode (NewExpressionNodeVariable (name, modifiers));
	dAssert (returnNode.m_node->GetTypeId() == dDAGExpressionNodeVariable::GetRttiType());
	dDAGExpressionNodeVariable* const node = (dDAGExpressionNodeVariable*) returnNode.m_node;
	node->SetType((dDAGTypeNode*) typeNode->Clone (m_allNodes));
	return returnNode;
}
NewtonBody* CreateSimpleSolid (DemoEntityManager* const scene, DemoMesh* const mesh, dFloat mass, const dMatrix& matrix, NewtonCollision* const collision, int materialId, bool generalInertia)
{
	dAssert (collision);

	// add an new entity to the world
	DemoEntity* const entity = new DemoEntity(matrix, NULL);
	scene->Append (entity);
	if (mesh) {
		entity->SetMesh(mesh, dGetIdentityMatrix());
	}
	return CreateSimpleBody (scene->GetNewton(), entity, mass, matrix, collision, materialId, generalInertia);
}
void dCILInstrReturn::AddUsedVariable (dInstructionVariableDictionary& dictionary) const 
{
	dAssert (!m_arg0.GetType().m_isPointer);
	switch (m_arg0.GetType().m_intrinsicType) 
	{
		case m_int:
		{
			dInstructionVariableDictionary::dTreeNode* const node = dictionary.Insert(m_arg0.m_label);
			node->GetInfo().Append(m_myNode);
			break;
		}

		case m_void:
		case m_constInt:
			break;

		default:
			dAssert(0);
		}

}
dDAGTypeNode::dDAGTypeNode(dList<dDAG*>& allNodes, const dDAGTypeNode& copySource)
	:dDAG(allNodes)
	,m_dimensions(copySource.m_dimensions)
	,m_type (copySource.m_type)
{
	m_name = copySource.m_name;
	for (dList<dDAGDimensionNode*>::dListNode* node = copySource.m_dimensions.GetFirst(); node; node = node->GetNext()) {
		dAssert (m_type.m_isPointer);
		dDAGDimensionNode* const dim = node->GetInfo();
		m_dimensions.Append ((dDAGDimensionNode*)dim->Clone(allNodes));
	}
}
DemoBezierCurve::DemoBezierCurve(const dScene* const scene, dScene::dTreeNode* const bezierNode)
	:DemoMeshInterface()
	,m_curve()
	,m_renderResolution(50)
{
	m_isVisible = false;
	dLineNodeInfo* const bezeriInfo = (dLineNodeInfo*)scene->GetInfoFromNode(bezierNode);
	dAssert (bezeriInfo->IsType(dLineNodeInfo::GetRttiType()));
	m_name = bezeriInfo->GetName();

	m_curve = bezeriInfo->GetCurve();
}
// draw scene in solid wire frame mode
void dRigidbodyNodeInfo::DrawSolidWireFrame(dScene* const world, dScene::dTreeNode* const myNode, const dVector& color) const
{
	dAssert (world->GetInfoFromNode(myNode) == this);
	dAssert (myNode == world->Find(GetUniqueID()));
dAssert (0);
/*
	dScene::dTreeNode* geomNode = world->FindChildByType(myNode, dGeometryNodeInfo::GetRttiType());
	if (geomNode) {

		glPushMatrix();
		dMatrix matrix (GetTransform());
		//glMultMatrix(&matrix[0][0]);
		glLoadMatrix(&matrix[0][0]);

		dGeometryNodeInfo* gemInfo = (dGeometryNodeInfo*) world->GetInfoFromNode(geomNode);
		gemInfo->DrawSolidWireFrame(world, geomNode, color, workBuffer, worlfBufferInBytes);

		glPopMatrix();
	}
*/
}
dScriptCompiler::dUserVariable dScriptCompiler::NewExpressionNodeVariable (const dString& name, const dString& modifiers, const dUserVariable& dimArray)
{
	dUserVariable returnNode;

//	_ASSERTE (GetCurrentScope());
	dDAGDimensionNode* const dimensionNode = (dDAGDimensionNode*) dimArray.m_node;
	dAssert (!dimensionNode || dimensionNode->IsType(dDAGDimensionNode::GetRttiType()));

	dDAGExpressionNodeVariable* const node = new dDAGExpressionNodeVariable (m_allNodes, name, modifiers, dimensionNode);
	returnNode.m_node = node;
	return returnNode;
}
dScriptCompiler::dUserVariable dScriptCompiler::NewExpressionFunctionCall (const dString& name, const dUserVariable& argumnetList)
{
	dUserVariable returnNode;

	//dAssert (m_currentFunction);
	dDAGExpressionNode* const argumentListNode = (dDAGExpressionNode*) argumnetList.m_node;
	dAssert (!argumentListNode || argumentListNode->IsType(dDAGExpressionNode::GetRttiType()));
	dDAGExpressionNodeFunctionCall* const fntCall = new dDAGExpressionNodeFunctionCall(m_allNodes, name.GetStr(), argumentListNode);

	returnNode.m_node = fntCall;
	return returnNode;
}
void dDAGFunctionNode::EmitLLVMGoto (dLLVMSymbols& localSymbols, dCIL::dListNode* const stmtNode, llvm::BasicBlock* const llvmBlock, llvm::LLVMContext &context)
{
dAssert (0);
/*

	const dThreeAdressStmt& stmt = stmtNode->GetInfo();
	dAssert (stmt.m_operator == dThreeAdressStmt::m_nothing);
	llvm::BasicBlock* const targetBlock = m_blockMap.Find (stmt.m_trueTargetJump);
	dAssert (targetBlock);
	llvm::BranchInst::Create (targetBlock, llvmBlock);
*/
}
Beispiel #23
0
CustomVehicleControllerBodyStateContact* CustomVehicleController::GetContactBody (const NewtonBody* const body)
{
	for (int i = 0; i < m_externalContactStatesCount; i ++) {
		if (m_externalContactStates[i]->m_newtonBody == body) {
			return m_externalContactStates[i];
		}
	}

	dAssert (m_externalContactStatesPoll.GetCount() < 32);
	if (!m_freeContactList) {
		m_freeContactList = m_externalContactStatesPoll.Append();
	}
	CustomVehicleControllerBodyStateContact* const externalBody = &m_freeContactList->GetInfo();
	m_freeContactList = m_freeContactList->GetNext(); 
	externalBody->Init (this, body);
	m_externalContactStates[m_externalContactStatesCount] = externalBody;
	m_externalContactStatesCount ++;
	dAssert (m_externalContactStatesCount < int (sizeof (m_externalContactStates) / sizeof (m_externalContactStates[0])));

	return externalBody;
}
void dComplentaritySolver::dBodyState::IntegrateVelocity (dFloat timestep)
{
	const dFloat D_MAX_ANGLE_STEP = dFloat (45.0f * 3.141592f / 180.0f);
	const dFloat D_ANGULAR_TOL = dFloat (0.0125f * 3.141592f / 180.0f);

	m_globalCentreOfMass += m_veloc.Scale (timestep); 
	while (((m_omega % m_omega) * timestep * timestep) > (D_MAX_ANGLE_STEP * D_MAX_ANGLE_STEP)) {
		m_omega = m_omega.Scale (dFloat (0.8f));
	}

	// this is correct
	dFloat omegaMag2 = m_omega % m_omega;
	if (omegaMag2 > (D_ANGULAR_TOL * D_ANGULAR_TOL)) {
		dFloat invOmegaMag = 1.0f / dSqrt (omegaMag2);
		dVector omegaAxis (m_omega.Scale (invOmegaMag));
		dFloat omegaAngle = invOmegaMag * omegaMag2 * timestep;
		dQuaternion rotation (omegaAxis, omegaAngle);
		dQuaternion rotMatrix (m_matrix);
		rotMatrix = rotMatrix * rotation;
		rotMatrix.Scale( 1.0f / dSqrt (rotMatrix.DotProduct (rotMatrix)));
		m_matrix = dMatrix (rotMatrix, m_matrix.m_posit);
	}

	m_matrix.m_posit = m_globalCentreOfMass - m_matrix.RotateVector(m_localFrame.m_posit);

#ifdef _DEBUG
	int j0 = 1;
	int j1 = 2;
	for (int i = 0; i < 3; i ++) {
		dAssert (m_matrix[i][3] == 0.0f);
		dFloat val = m_matrix[i] % m_matrix[i];
		dAssert (dAbs (val - 1.0f) < 1.0e-5f);
		dVector tmp (m_matrix[j0] * m_matrix[j1]);
		val = tmp % m_matrix[i];
		dAssert (dAbs (val - 1.0f) < 1.0e-5f);
		j0 = j1;
		j1 = i;
	}
#endif
}
void dDAGFunctionNode::EmitLLVMLoadBase (dLLVMSymbols& localSymbols, dCIL::dListNode* const stmtNode, llvm::BasicBlock* const llvmBlock, llvm::LLVMContext &context)
{
dAssert (0);
/*

	const dThreeAdressStmt& stmt = stmtNode->GetInfo();
	dAssert (localSymbols.Find (stmt.m_arg1.m_label));
	llvm::Value* const src = localSymbols.Find (stmt.m_arg1.m_label)->GetInfo();
	llvm::LoadInst* const local = new llvm::LoadInst (src, stmt.m_arg0.m_label.GetStr(), false, llvmBlock);
	local->setAlignment(4);
	localSymbols.Insert(local, stmt.m_arg0.m_label.GetStr()) ;
*/
}
void dDAGFunctionNode::EmitLLVMStoreBase (dLLVMSymbols& localSymbols, dCIL::dListNode* const stmtNode, llvm::BasicBlock* const llvmBlock, llvm::LLVMContext &context)
{
dAssert (0);
/*
	const dThreeAdressStmt& stmt = stmtNode->GetInfo();
	dAssert (localSymbols.Find (stmt.m_arg0.m_label));
	llvm::Value* const dst = localSymbols.Find (stmt.m_arg0.m_label)->GetInfo();
	llvm::Value* const src = GetLLVMConstantOrValue (localSymbols, stmt.m_arg1, context);

	llvm::StoreInst* const local = new llvm::StoreInst(src, dst, false, llvmBlock);
	local->setAlignment(4);
*/
}
int dComplentaritySolver::dFrictionLessContactJoint::ReduceContacts (int count, dContact* const contacts, dFloat tol)
{
	int mask[D_MAX_PLACEMENT_CONTACTS];
	int index = 0;
	int packContacts = 0;
	dFloat window = tol;
	dFloat window2 = window * window;
	memset (mask, 0, size_t (count));
	dSort (contacts, count, CompareContact, NULL);
	dAssert (count <= D_MAX_PLACEMENT_CONTACTS);
	for (int i = 0; i < count; i ++) {
		if (!mask[i]) {
			dFloat val = contacts[i].m_point[index] + window;
			for (int j = i + 1; (j < count) && (contacts[j].m_point[index] < val) ; j ++) {
				if (!mask[j]) {
					dVector dp (contacts[j].m_point - contacts[i].m_point);
					dFloat dist2 = dp % dp;
					if (dist2 < window2) {
						mask[j] = 1;
						packContacts = 1;
					}
				}
			}
		}
	}

	if (packContacts) {
		int j = 0;
		for (int i = 0; i < count; i ++) {
			dAssert (i < D_MAX_PLACEMENT_CONTACTS);
			if (!mask[i]) {
				contacts[j] = contacts[i];
				j ++;
			}
		}
		count = j;
	}
	return count;
}
CustomArticulatedTransformController::dSkeletonBone* CustomArticulatedTransformController::AddBone (NewtonBody* const bone, const dMatrix& bindMatrix, dSkeletonBone* const parentBone)
{
	m_bones[m_boneCount].m_body = bone;
	m_bones[m_boneCount].m_myController = this;
	m_bones[m_boneCount].m_parent = parentBone;
	m_bones[m_boneCount].m_bindMatrix = bindMatrix;

	NewtonCollisionAggregateAddBody (m_collisionAggregate, bone);

	m_boneCount ++;
	dAssert (m_boneCount < D_HIERACHICAL_CONTROLLER_MAX_BONES);
	return &m_bones[m_boneCount - 1];
}
Beispiel #29
0
	// implement a ray cast pre-filter
	static unsigned RayCastPrefilter (const NewtonBody* body,  const NewtonCollision* const collision, void* const userData)
	{
		// ray cannot pick trigger volumes
		//return NewtonCollisionIsTriggerVolume(collision) ? 0 : 1;

		const NewtonCollision* const parent = NewtonCollisionGetParentInstance(collision);
		if (parent) {
			// you can use this to filter sub collision shapes.  
			dAssert (NewtonCollisionGetSubCollisionHandle (collision));
		}

		return (NewtonBodyGetType(body) == NEWTON_DYNAMIC_BODY) ? 1 : 0;
	}
bool dCILInstrMove::ApplyDeadElimination (dDataFlowGraph& dataFlow)
{ 
	dAssert(0);
	return 0;
/*
	if (m_arg0.m_label == m_arg1.m_label) {
		Nullify();
		dataFlow.UpdateLiveInputLiveOutput();
		return true;
	}
	return DeadElimination (dataFlow);
*/
}