// // 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" //Create a maya command called 'sphere_sphere_angular_collision_reaction' that //will call the doIt function DeclareSimpleCommand( sphere_sphere_intersection, "Jedrik D. Eliasen", "7.0"); //this function is what Maya will process MStatus sphere_sphere_intersection::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 paramater variables float velocity; double radius1, radius2; double translationS1[3]; double translationS2[3]; double rotation[3]; char temp1[10],temp2[10],temp3[10], temp4[10]; unsigned index; //set the 1st sphere's position x coord to translationS1[x] index = args.flagIndex( "tx1", "translateS1X"); args.get(index + 1, translationS1[x]); //set the 1st sphere's position y coord to translationS1[y] index = args.flagIndex( "ty1", "translateS1Y"); args.get(index + 1, translationS1[y]); //set the 1st sphere's position z coord to translationS1[z] index = args.flagIndex( "tz1", "translateS1Z"); args.get(index + 1, translationS1[z]); //set the 1st sphere's radius to radius1 index = args.flagIndex( "r1", "radius1"); args.get(index + 1, radius1); //set the 1st sphere's position x coord to translationS2[x] index = args.flagIndex( "tx2", "translateS2X"); args.get(index + 1, translationS2[x]); //set the 2nd sphere's position y coord to translationS2[y] index = args.flagIndex( "ty2", "translateS2Y"); args.get(index + 1, translationS2[y]); //set the 2nd sphere's position z coord to translationS2[z] index = args.flagIndex( "tz2", "translateS2Z"); args.get(index + 1, translationS2[z]); //set the 2nd sphere's radius to radius2 index = args.flagIndex( "r2", "radius2"); args.get(index + 1, radius2); //set the centers of the spheres to two vectors Vec3f vec1(translationS1[x],translationS1[y],translationS1[z]); Vec3f vec2(translationS2[x],translationS2[y],translationS2[z]); Vec3f pointXn(0,0,0); bool is_intersection = false; //////////////////////////////////////////////////////////////////////////////// Vec3f DistanceVector = vec1 - vec2; float DistanceMagnitude = DistanceVector.GetMag(); if( DistanceMagnitude > radius1 + radius2) { is_intersection = false; } else { pointXn = vec1 - vec2; pointXn.normalize(); pointXn = pointXn*radius1 + vec1; is_intersection = true; } //////////////////////////////////////////////////////////////////////////////// //'return' is_intersection to MEL clearResult(); setResult( is_intersection ); //this will return to MEL a true or false depending on whether the function //was successful or not return stat; }