Notifications
Clear all

[Closed] SDK IntersectRay

Hey, I’m trying to convert the Maxscripts Move Objects to Surface script (from the Maxscript Online Help) to C++, but the IntersectRay seems to work different on the SDK. Can anyone help ?
Also, I’ve read in a few places that IntersectRay isn’t that fast, so is there a different method to do this all together ??

Here is the Maxscript version:

node1 = $Box001
  plane1 = $Plane001
  
  fn find_intersection z_node node_to_z =
  	( 
  		local testRay = ray node_to_z.pos [0,0,-1] 
  		local nodeMaxZ = z_node.max.z 
  		testRay.pos.z = nodeMaxZ + 0.0001 * abs nodeMaxZ 
  		intersectRay z_node testRay 
  	)
  int_point = find_intersection plane1 node1
  if int_point != undefined then print("Found intersection")

Heres my C++ version atm:

	INode* box = ip->GetINodeByName(L"Box001");
  	INode* plane = ip->GetINodeByName(L"Plane001");
  	if(box && plane){
  		Ray testRay;
  		testRay.p = box->GetNodeTM(t).GetTrans();
  		testRay.dir = Point3(0, 0, -1);
  		Object* obj = plane->GetObjectRef();
  		float pt;
  		Point3 norm;
  		if(obj->IntersectRay(t, testRay, pt, norm) != 0){
  			ExecuteMAXScriptScript(_T("print \"Found Intersect\""), 0, 0);
  		}
  	}
3 Replies

the mxs version works in world space the sdk routine it uses works in local object space

here’s the function…

and yes it is relatively slow

Ok, slighty different question but what is with the Value function ?? I see it all over the SDK, but I never see it being called.
Probably a really newbish question, but how does it work?

Value is the data type all mxs types are derived from,