30 likes | 137 Views
3D Game Programming Homework Assignment # 2 Write a program to hit test the 3D position on 3D objects. The scene data (in the HW02 folder) : test_scene.cwn In the same folder, there are the associated texture files. Requirements :
E N D
3D Game Programming Homework Assignment # 2 • Write a program to hit test the 3D position on 3D objects. • The scene data (in the HW02 folder) : test_scene.cwn • In the same folder, there are the associated texture files. • Requirements : • Show camera current position, facing direction, and up direction on screen. • Press and hold the SHIFT key to use the mouse button to hit test any point on a 3D model object. • Show the hitting result on screen, including the hit object name and the 3D position. Just the demo program showed on screen. • A to-be-finished reference example (in src folder) : HomeWork02.cpp • Deadline : 1128/2005
Hints : • To load a scene file, please use the scene.Load(). For example, • // query the number of objects in a scene file (.cwn) • numObj = scene.QueryObjectNumberInFile("test_scene"); • // load the scene and query all loaded objects • objID = (OBJECTid *)malloc(sizeof(OBJECTid)*numObj); • scene.Load("test_scene", objID); • 2. To show messages on screen : • // start to show message • FnWorld gw; • gw.Object(gID); • gw.StartMessageDisplay(); • // show messages • gw.MessageOnScreen(20, 15, string1, 255, 0, 0); • gw.MessageOnScreen(20, 30, string2, 255, 0, 0); • … • // finish the message displaying • gw.FinishMessageDisplay();
3. To hit test a 3D object, use the member function of a viewport function : FnViewport::HitPosition(obj_to_be_Hit, cam_ID, screenX, screenY, result) 4. To make sure the hit result is nearest to the camera, you need to check the distance between the hit point and the camera. Compared the hit result for each object to make sure the final result is nearest one.