gamecreator Posted January 15, 2012 Share Posted January 15, 2012 Could someone please let me know why CameraPick doesn't pick model in the following code? #include "engine.h" int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd) { Initialize(); Graphics(640,480); TFramework fw = CreateFramework(); SetGlobalObject("fw",fw); TCamera camera=GetLayerCamera(GetFrameworkLayer(0)); PositionEntity(camera,Vec3(0,5,-12)); RotateEntity(camera,Vec3(15,0,0)); TLight light=CreateDirectionalLight(); RotateEntity(light,Vec3(45,45,45)); TMesh cube=CreateCube(); EntityType(cube,1); TMesh model=LoadModel("abstract::frame.gmf"); PositionEntity(model,Vec3(1,1,0)); EntityType(model,1); Collisions(1,1,true); while(!KeyHit(KEY_ESCAPE)) { TPick pick; UpdateFramework(); RenderFramework(); if(CameraPick(&pick,camera,Vec3(MouseX(),MouseY(),1000),0,1)) DrawText(0,20,"HIT"); Flip(0); } return 1; } As it stands, CameraPick only picks the cube. If I change the collision type to 0, it selects both the cube and the model. Any ideas? Quote Link to comment Share on other sites More sharing options...
macklebee Posted January 15, 2012 Share Posted January 15, 2012 because a raycast only works on meshes/terrains... so search the forum for GetMeshModel and you will find several examples that show how to do this... Quote Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590 LE / 3DWS / BMX / Hexagon macklebee's channel Link to comment Share on other sites More sharing options...
gamecreator Posted January 15, 2012 Author Share Posted January 15, 2012 That makes sense but I wonder why it picks it when collision type is 0. Will look into that function. Thank you. Edit: On first glance, it looks like that function returns a body, not a mesh... Quote Link to comment Share on other sites More sharing options...
macklebee Posted January 15, 2012 Share Posted January 15, 2012 when the raycast collision type is set to 0, it returns everything it hits regardless of the entity's collision type Also, the third parameter for Collisions() is not boolean... Quote Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590 LE / 3DWS / BMX / Hexagon macklebee's channel Link to comment Share on other sites More sharing options...
gamecreator Posted January 15, 2012 Author Share Posted January 15, 2012 Right, but then it hits both meshes and models for some reason. It would be nice if it hit meshes and models if the collision type was specified too. And that third parameter was copied from the Josh's Collisions_and_Raycasting.PDF from the source example but I knew better. Quote Link to comment Share on other sites More sharing options...
gamecreator Posted January 15, 2012 Author Share Posted January 15, 2012 After some detective work, I found what I did wrong. CameraPick works on models too, but not directly. It can pick the model's child, which is the mesh. My mistake was that I didn't specify the third parameter of EntityType, the recursion. As it's shown in the code above, it's 0 by default, which doesn't change the model's mesh entity type. But specify it as 1, and the mesh child (and so the model), will be properly picked, like so: EntityType(model,1,1); Live and learn. Thank you for your help mackelbee. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.