Logically you never should create this TVCollisionResult class.
The class is returned by MousePick function, and is created inside the MousePick function.
I called Scene->MousePick function before check collision but it still crashes.
can you please see my code and point me what's wrong?
#include "Header.h"
// Declare TrueVision
ITVEngine TV;
ITVGlobals Globals;
ITVInputEngine Input;
ITVScene Scene;
ITVLandscape Land;
ITVTextureFactory TexFactory;
ITVCollisionResult CollisionResult;
ITVScreen2DText Text;
void InitializeEngine(HWND hWnd)
{
ShowCursor(false);
// Create Everything
TV = CreateTVEngine();
Globals = CreateTVGlobals();
Input = CreateTVInputEngine();
Scene = CreateTVScene();
Land = CreateTVLandscape();
TexFactory = CreateTVTextureFactory();
CollisionResult = CreateTVCollisionResult();
Text = CreateTVScreen2DText();
// Initialize
TV->Init3DWindowedMode((long)hWnd,tvtrue); // windowed mode, support TnL
TV->put_DisplayFPS(tvfalse); // don't display fps
TV->SetSearchDirectory("."); // set current directory
Scene->SetSceneBackGround(0,0,1); // clear background with blue
Scene->LoadCursor("..\\media\\pointer.bmp",TV_COLORKEY_BLACK,32,16); // load in-game cursor
Scene->SetCamera(0,50,550,150,100,550);
Land->GenerateHugeTerrain("..\\media\\heightmap.jpg",TV_PRECISION_LOW,8,8,0,0,tvtrue); // generate landscape
TexFactory->LoadTexture("..\\media\\sand.jpg","tex_sand",-1,-1,TV_COLORKEY_NO,tvtrue,tvtrue); // load landscape texture
Land->SetTexture(Globals->GetTex("tex_sand"),-1); // set landscape texture
long font = Text->TextureFont_Create("def_font","Arial",16,tvtrue,tvfalse,tvfalse,tvfalse); // create Arial font
}
void ShutdownEngine()
{
// Release All
Text->Release();
CollisionResult->Release();
TexFactory->Release();
Land->Release();
Scene->Release();
Input->Release();
Globals->Release();
TV->Release();
Text = NULL;
CollisionResult = NULL;
TexFactory = NULL;
Land = NULL;
Scene = NULL;
Input = NULL;
Globals = NULL;
TV = NULL;
}
void RenderScenes()
{
if(Input->IsKeyPressed(TV_KEY_ESCAPE)) // check if user press escape key
PostQuitMessage(0); // then quit the app
TV->Clear(tvfalse); // clear backbuffer (not z-buffer only)
long mX,mY;
short button;
Input->GetAbsMouseState(&mX,&mY,&button,&button,&button); // get mouse state
CollisionResult = Scene->MousePicking(mX,mY,TV_COLLIDE_LANDSCAPE,TV_TESTTYPE_ACCURATETESTING);
if(CollisionResult->IsCollision()) // BUG !!!!!!!!!!!!!!!!!!!!!!!!!!!
{
char buff[256];
sprintf(buff,"X : %.2f Y : %.2f Z : %.2f",CollisionResult->GetImpactPoint().x,CollisionResult->GetImpactPoint().y,CollisionResult->GetImpactPoint().z);
Text->TextureFont_DrawText(buff,5,5,RGBA(1,1,1,1),"");
}
Land->Render(tvtrue,tvtrue); // render landscape
TV->RenderToScreen(); // render scene
}