Jump to content

gamecreator
 Share

Recommended Posts

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...