Search Home Members Contacts
About Us
Products
Downloads
Community
Support
Pages: [1]
  Print  
Author Topic: [Newb] Problem with Load() in Actor2  (Read 685 times)
hualimz
Community Member
*
Posts: 24


« on: April 13, 2009, 09:48:44 AM »

Hi, I just modified tutorial10 (Moving Tank) and try to change actor from tank.md3 to my model "doom.x" which I already copied to same dir as tank.md3

Alright , I've modified TVActor to TVActor2 here
Code:
ITVActor pTankActor; >> ITVActor2 pTankActor;

and then...

Code:
pTankActor = pScene->CreateActorTVM("doom");
pTankActor->Load("..\\..\\..\\Media\\Doom.x","doom",tvtrue, tvtrue);

and then Render();
Compile ok! and when it runs I've "Unhandled Exception" and kind of "Access Violation"

Please, I tried to search over the forums and read the manual for 3 hrs.

anyway this is the code after my mod

Code:
#include "stdafx.h"
#include <math.h>
#include "..\tv3dcpp.h"

//Setup TrueVision3D
ITVEngine pEngine;
ITVInputEngine pInput;
ITVGlobals pGlobals;
ITVScene pScene;
ITVTextureFactory pTexFactory;
ITVLandscape pLand;
ITVAtmosphere pAtmos;
ITVActor2 pTankActor;

void render();
void input();
void unload();


float fTimeElapsed = 0.0;

float sngPositionX = 0.0;
float sngPositionY = 0.0;
float sngPositionZ = 0.0;
float sngAngleX = 0.0;
float sngAngleY = 0.0;

//We could have done this in many ways, but we added some smoothing to
//the movement se we need to declare two additional variables.
float sngWalk = 0.0;
float sngStrafe = 0.0;
float sngBrake = 0.0;

//Declare a water height variable
float sngWaterHeight = 0.0;

D3DVECTOR* TankPosition;

LRESULT CALLBACK WndProc(HWND wpHWnd, UINT msg, WPARAM wParam, LPARAM lParam);

//WinMain: The entry point to everything Windows
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
HWND WindowHandle;

WNDCLASSEX wc = { sizeof(WNDCLASSEX), CS_CLASSDC, WndProc, 0L, 0L,
                      GetModuleHandle(NULL), NULL, NULL, NULL, NULL,
                      "TV3D Tutorial", NULL };
  RegisterClassEx(&wc);

WindowHandle = CreateWindow( "TV3D Tutorial", "TV3D Tutorial A09: Controlling a Tank",
                              WS_OVERLAPPEDWINDOW, 100, 100, 640, 480,
                              GetDesktopWindow(), NULL, wc.hInstance, NULL );

// there is a problem creating the window
if (WindowHandle ==  NULL)
{
MessageBox(NULL, "Unable to Create a Window", "Error", MB_OK);
return false;
}


  ShowWindow (WindowHandle, 1);
  UpdateWindow (WindowHandle);
  SetFocus (WindowHandle);
  ShowCursor (TRUE);

//Initialze COM
CoInitialize(NULL);

pEngine = CreateTVEngine();

//Engine Running boolean
double Gamma = 0.0;
MSG msg;

//Set the debug file before doing anything else
pEngine->SetDebugFile ("c:\\debug.txt");

//Initialize Windowed
pEngine->Init3DWindowedMode ((long)WindowHandle, true);

//Tell it to display the FPS
pEngine->put_DisplayFPS(tvtrue);

//AppPath is a small Macro function in tv3dcpp lib to return the path
//of a file you pass to it, in this case we get the application path
char path[256];
char srchpath[256];

HMODULE Module = (HMODULE)hInstance;
GetModuleFileName(Module,path,255);

AppPath(path,srchpath);

//Set the search directory of the objects, textures, ...
pEngine->SetSearchDirectory(srchpath);

//We set the AngleSystem to Degrees
pEngine->SetAngleSystem (TV_ANGLE_DEGREE);

//Init input after main init, and check if it errors anywhere.
pInput = CreateTVInputEngine();
pScene = CreateTVScene();
pGlobals = CreateTVGlobals();
pTexFactory = CreateTVTextureFactory();
pLand = CreateTVLandscape();
pAtmos = CreateTVAtmosphere();
pTankActor = pScene->CreateActorTVM("Tanky");

    pScene->SetSceneBackGround( 0.0f, 0.3f, 0.9f);

  //Generate the height of the land from the grayscale of the image.
    pLand->GenerateHugeTerrain("..\\..\\..\\Media\\Heightmaps\\track.jpg", TV_PRECISION_LOW, 8, 8, -700, -1024, tvtrue);
   
    //Then, we load the land texture.
    pTexFactory->LoadTexture("..\\..\\..\\Media\\sand.jpg", "LandTexture", -1, -1, TV_COLORKEY_NO, tvtrue, tvtrue);
   
    //We assign a texture to that land.
    pLand->SetTexture(pGlobals->GetTex("LandTexture"),-1);

    //Now, load our model.
pTankActor->Load("..\\..\\..\\Media\\Doom.x","doom",tvtrue, tvtrue);

    //Load the texture and assign it.
pTexFactory->LoadTexture( "..\\..\\..\\Media\\tank.bmp", "TankTexture", -1, -1, TV_COLORKEY_NO, tvtrue, tvtrue);
pTankActor->SetTexture ( pGlobals->GetTex("TankTexture"),-1);

TankPosition = new D3DVECTOR;
TankPosition->x = 50;
TankPosition->z = 50;
TankPosition->y = pLand->GetHeight(TankPosition->x, TankPosition->z);
pTankActor->SetPosition(TankPosition->x, TankPosition->y, TankPosition->z);

//Something else new : we set the camera vectors which are the
    //position of the camera (the point of view) and where we are
    //looking at. We start by centering the camera position at the
    //vector 0,20,0 and the look at the vector 50,20,50
    sngPositionX = 0;
    sngPositionY = 20;
    sngPositionZ = 0;
    sngAngleX = 0;
    sngAngleY = 0;
   
    //We set the initial values of movement
    sngWalk = 0;
    sngStrafe = 0;

//Main loop
while( msg.message!=WM_QUIT)
{
if(PeekMessage( &msg, NULL, 0U, 0U, PM_REMOVE ) )
{
TranslateMessage( &msg );
DispatchMessage( &msg );
}
else
{
input();
render();
}
}

unload();

//Exit sucessfully
return 0;
}

//Render sub
void render()
{
pEngine->Clear(tvfalse); //Clear the screen
pAtmos->Atmosphere_Render();
pLand->Render(tvtrue, tvtrue);
pTankActor->Render();
pEngine->RenderToScreen (); //Render the screen
}

//Input sub
void input()
{
    //Check if we pressed the UP arrow key, if so, then we are
    //walking forward.
    if(pInput->IsKeyPressed(TV_KEY_UP))
{
        sngWalk = 1;
}

    //Check if we pressed the DOWN arrow key, if so, then we are
    //pressing the breaks.
    if(pInput->IsKeyPressed(TV_KEY_DOWN))
    {       
        sngBrake = (float)0.002;
}   
    else
    {   
//We are not pressing the brakes, let the tank float.
        sngBrake = (float)0.0005; 
    }

    //Check if we pressed the LEFT arrow key, if so, then strafe
    //on the left.
    if(pInput->IsKeyPressed(TV_KEY_LEFT))
    {
        sngStrafe = 1;
}               
    //If we are not strafing left, maybe we want to strafe to the
    //right, using the RIGHT arrow? If so, set strafe to negative.
    if(pInput->IsKeyPressed(TV_KEY_RIGHT))
    {
        sngStrafe = -1;
    }

    //Now, for the mouse input...
    long tmpMouseX = 0; long tmpMouseY = 0;
    long tmpMouseB1 = 0; long tmpMouseB2 = 0; long tmpMouseB3 = 0;
    long tmpMouseScrollOld = 0; long tmpMouseScrollNew = 0;

    //Get the movement of the mouse.
    pInput->GetMouseState(&tmpMouseX, &tmpMouseY, (short *)&tmpMouseB1, (short *)&tmpMouseB2, (short *)&tmpMouseB3, &tmpMouseScrollNew);

//Update the tank angle.
    sngAngleY -= tmpMouseX / 100;

    //Okay, now for the smothing of the movement... Update
    //the forward and backward (walk) movement.

fTimeElapsed = pEngine->TimeElapsed();
    if( sngWalk > 0)
{
        sngWalk -= sngBrake * fTimeElapsed;
        if(sngWalk < 0) sngWalk = 0;
    }
   
    //Now, we update the left and right (strafe) movement.
  fTimeElapsed = pEngine->TimeElapsed();

    if( sngStrafe > 0.0f)
{
        sngStrafe -= 0.001f * fTimeElapsed;
        if(sngStrafe < 0.0f)
{
sngStrafe = 0.0f;
}
}

if( sngStrafe < 0.0f)
{
        sngStrafe += 0.001f * fTimeElapsed;
        if(sngStrafe > 0.0f)
{
sngStrafe = 0.0f;
}
    }
   
    //Update the vectors using the angles and positions. But this
    //time, we don't update the camera position but the tank
//vector position.
    TankPosition->x += (cosf(sngAngleY) * sngWalk / 5.0f * fTimeElapsed) + (cosf(sngAngleY + 3.141596f / 2.0f) * sngStrafe / 5.0f * fTimeElapsed);
    TankPosition->z += (sinf(sngAngleY) * sngWalk / 5.0f * fTimeElapsed) + (sinf(sngAngleY + 3.141596f / 2.0f) * sngStrafe / 5.0f * fTimeElapsed);
    TankPosition->y = pLand->GetHeight(TankPosition->x, TankPosition->z) + 10;
   
    //From the tank position vector, we update the mesh position.
    pTankActor->SetPosition( TankPosition->x, TankPosition->y, TankPosition->z);

    //From the angle variable, we update the tank rotation, and from
    //the strafe speed, we update the tank roll.
    pTankActor->SetRotation(-90.0f + (sngStrafe * 10.0f), (sngAngleY * -57.295f), 0.0f);

//With the new values of the tank vector, we update the camera
    //position and look at.
    float tmpLookAtX = 0.0f; float tmpLookAtZ = 0.0f; float tmpLookAtY = 0.0f;
    tmpLookAtX = TankPosition->x - (cosf(sngAngleY) * 40.0f);
    tmpLookAtZ = TankPosition->z - (sinf(sngAngleY) * 40.0f);
    tmpLookAtY = pLand->GetHeight(tmpLookAtX, tmpLookAtZ) + 20.0f;
 
    //With the new values of the tank vector, we update the camera
    //position and look at.
    pScene->SetCamera(tmpLookAtX, tmpLookAtY, tmpLookAtZ, TankPosition->x, TankPosition->y, TankPosition->z);

if(pInput->IsKeyPressed(TV_KEY_ESCAPE)) //Check if ESCAPE has been pressed.
{
PostQuitMessage(0);
}
}

//Unload sub
void unload()
{
//Uninitialize the variables
pTankActor->Release ();
pTankActor=NULL;

pAtmos->Release ();
pAtmos=NULL;

pLand->Release();
pLand=NULL;

pScene->Release ();
pScene = NULL;

pInput->Release ();
pInput = NULL;

pGlobals->Release ();
pGlobals=NULL;

pEngine->Release ();
pEngine = NULL;

//Uninitialize COM
CoUninitialize();
}

LRESULT CALLBACK WndProc(HWND wpHWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{

switch(msg)
{
case WM_DESTROY:
{
PostQuitMessage(0);
return 0;
} break;


default:break;
}


return DefWindowProc(wpHWnd, msg, wParam, lParam);

}






Logged
nadjibus
Community Member
*
Posts: 250

Heavy Dev Process


« Reply #1 on: April 13, 2009, 09:58:46 AM »

Why are you using Scene.CreateActorTVM ?? I didnt used 6.3 for long time I forgot instructions and methods but you have an X File (Mulder  Grin) not a TVM... is there a scene.CreateActorX or CreateActor2 or anything else??

And if you're a beginner, why u dont with 6.5 it's better! 6.3 is obselete.

Peace.
Logged

hualimz
Community Member
*
Posts: 24


« Reply #2 on: April 13, 2009, 10:55:11 AM »

Yeah, I guess i'll have to use 6.5
I'll try it tomorrow then.  Anyway, thank you!
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by SMF 1.1.3 | SMF © 2006-2007, Simple Machines LLC
Seo4Smf v0.2 © Webmaster's Talks