// // Copyright (C) Jedrik D. Eliasen // // File: rigidbody_pluginCmd.cpp #pragma once #include "stdio.h" #include #include #include #include #include #include "Vec3f.h" #include "Plane.h" #include "math.h" //Create a maya command called 'plane_sphere_intersection' that //will call the doIt function DeclareSimpleCommand( plane_sphere_intersection, "Jedrik D. Eliasen", "7.0"); //this function is what Maya will process MStatus plane_sphere_intersection::doIt( const MArgList& args ) { MStatus stat = MS::kSuccess; //set x,y,z for simple array accessing int x = 0; int y = 1; int z = 2; //set the paramater variables double radius; double translationS[3]; double translationP[3]; double normal[3]; char temp1[10],temp2[10],temp3[10], temp4[10]; unsigned index; //set the sphere's position x coord to translationS[x] index = args.flagIndex( "stx", "translateSX"); args.get(index + 1, translationS[x]); //set the sphere's position y coord to translationS[y] index = args.flagIndex( "sty", "translateSY"); args.get(index + 1, translationS[y]); //set the sphere's position z coord to translationS[z] index = args.flagIndex( "stz", "translateSZ"); args.get(index + 1, translationS[z]); //set the sphere's radius to radius index = args.flagIndex( "r", "radius"); args.get(index + 1, radius); //set the plane's position x coord to translationP[x] index = args.flagIndex( "ptx", "translateS2X"); args.get(index + 1, translationP[x]); //set the plane's position y coord to translationP[y] index = args.flagIndex( "pty", "translateS2Y"); args.get(index + 1, translationP[y]); //set the plane's position z coord to translationP[z] index = args.flagIndex( "ptz", "translateS2Z"); args.get(index + 1, translationP[z]); //set the plane's normal x coord to normalX index = args.flagIndex( "nx", "normalX"); args.get(index + 1, normal[x]); //set the plane's normal y coord to normalY index = args.flagIndex( "ny", "normalY"); args.get(index + 1, normal[y]); //set the plane's normal z coord to normalZ index = args.flagIndex( "nz", "normalZ"); args.get(index + 1, normal[z]); //set the position of the sphere and plane, the plane's normal, //to our own type vector, Vec3f Vec3f s_center(translationS[x],translationS[y],translationS[z]); Vec3f p_center(translationP[x],translationP[y],translationP[z]); Vec3f p_normal(normal[x], normal[y], normal[z]); //////////////////////////////////////////////////////////////////////////////// bool is_intersection = false; float dotter = s_center.dot(p_normal); dotter = dotter*dotter; if ( dotter < radius*radius ) { is_intersection = true; } else { is_intersection = false; } //////////////////////////////////////////////////////////////////////////////// //'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; }