// // Copyright (C) Jedrik D. Eliasen // // File: rigidbody_pluginCmd.cpp #pragma once #include "stdio.h" #include #include #include #include #include "Vec3f.h" #include "Collision.h" #include "math.h" DeclareSimpleCommand( collision_occurance, "Jedrik D. Eliasen", "7.0"); MStatus collision_occurance::doIt( const MArgList& args ) { MStatus stat = MS::kSuccess; //set variables x,y,z to make array calls easier int x = 0; int y = 1; int z = 2; //set the double radius; double translationS[3]; double translationP[3]; double normal[3]; char temp1[10],temp2[10],temp3[10], temp4[10]; unsigned index; //get the attributes from sphere 1 and 2 from Maya index = args.flagIndex( "stx", "translateSX"); args.get(index + 1, translationS[x]); index = args.flagIndex( "sty", "translateSY"); args.get(index + 1, translationS[y]); index = args.flagIndex( "stz", "translateSZ"); args.get(index + 1, translationS[z]); index = args.flagIndex( "r", "radius"); args.get(index + 1, radius); index = args.flagIndex( "ptx", "translateS2X"); args.get(index + 1, translationP[x]); index = args.flagIndex( "pty", "translateS2Y"); args.get(index + 1, translationP[y]); index = args.flagIndex( "ptz", "translateS2Z"); args.get(index + 1, translationP[z]); index = args.flagIndex( "nx", "normalX"); args.get(index + 1, normal[x]); index = args.flagIndex( "ny", "normalY"); args.get(index + 1, normal[y]); index = args.flagIndex( "nz", "normalZ"); args.get(index + 1, normal[z]); //set the centers of the spheres to two vectors Vec3f vec1(translationS[x],translationS[y],translationS[z]); Vec3f vec2(translationP[x],translationP[y],translationP[z]); Vec3f n(normal[x], normal[y], normal[z]); Sphere s(vec1, radius); Plane p(vec2, n); //////////////////////////////////////////////////////////////////////////////// Collision_State State = NONE; //First, find out which side of the Plane and how far from the Plane the Sphere is, //via dot product of the Center and Plane Normal, negative means behind, positive means in front //float side = S1.COM_Position.dot(P1.Normal); float side = s.Center.dot(p.Normal); if ( side >= 0 && ( (side - s.Radius) < 0.01f ) && ( side - s.Radius) > -0.01f ) { State = TOUCHING; } else if ( side <= 0 && ( (side - s.Radius) < 0.01f ) && ( side - s.Radius) > -0.01f ) { State = TOUCHING; } else if ( side < s.Radius && side > 0) { State = OVERLAPPING; } else if ( side > s.Radius*-1.0f && side < 0 ) { State = OVERLAPPING; } else { State = NONE; } //////////////////////////////////////////////////////////////////////////////// if(State == NONE) MGlobal::displayInfo("NONE"); else if(State == OVERLAPPING) MGlobal::displayInfo("OVERLAPPING"); else if(State == TOUCHING) MGlobal::displayInfo("TOUCHING"); //clearResult(); //setResult( result ); return stat; }