Jump to content

Recommended Posts

Posted

Normally the access violation happens when we try to call a method of a pointer that's not pointing to anything. Below I get this on SetGravityMode() of the pivot. The pivot variable is valid as SetMass() works. What am I missing?

 

RTSCamera::RTSCamera(void)
{
     shape = Shape::Sphere(0, 0, 0, 1, 1, 1, 0, 0, 0);

     pivot = Pivot::Create();

     pivot->SetShape(shape);
     shape->AddRef();

     pivot->SetMass(1);
     pivot->SetGravityMode(false); /// gives me access violation
}

Posted

Hey Rick,

 

This works for me, I think the problem might be in your shape constructor as I think size is the 7th, 8th, 9th param so your box doesn't have a size.

 

Shape *shape = Shape::Box(0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.4F, 0.4F, 0.4F);

Pivot *pivot = Pivot::Create();
pivot->SetShape(shape);
shape->Release();

pivot->SetPhysicsMode(Entity::RigidBodyPhysics);
pivot->SetMass(10.0F);

trindieprod.png?dl=0spacer.png?dl=0steam-icon.png?dl=0twitter-icon.png?dl=0spacer.png?dl=0
Posted

FYI, you don't need to increment the shape ref count. It will automatically do that when you add it to the shape. Your normal usage shuld be like this:

shape = Shape::Sphere();
pivot = Pivot::Create();
pivot->SetShape(shape);
shape->Release();

  • Upvote 1

My job is to make tools you love, with the features you want, and performance you can't live without.

Posted

I still get access violation with the below code.

 

TJ I'm using a Sphere not a Box as in your example. I removed the params as the default does have a size but I get the same error.

 

shape = Shape::Sphere();
pivot = Pivot::Create();

pivot->SetShape(shape);
shape->Release();

pivot->SetPhysicsMode(Entity::RigidBodyPhysics);
pivot->SetMass(1);
pivot->SetGravityMode(false); // access violation

Posted

So I'm trying to get a RTS style camera where W always move forward, S moves backwards, etc but the camera is angled pointing down. I can't get the camera to move though. <man can we get the code formatting fixed for these forums sad.png >

 

header

#pragma once

#include "Leadwerks.h"

using namespace Leadwerks;

class RTSCamera
{
private:
    Pivot* pivot;
    Shape* shape;
public:
    RTSCamera(void);
    ~RTSCamera(void);

    void StartingPosition(Camera& camera);

    void Update(Window& window, Camera& camera);
};

 

source

#include "RTSCamera.h"


RTSCamera::RTSCamera(void)
{
    shape = Shape::Sphere();
    pivot = Pivot::Create();

    pivot->SetShape(shape);
    shape->Release();

    pivot->SetPhysicsMode(Entity::RigidBodyPhysics);
    pivot->SetMass(1);
    //pivot->SetGravityMode(false);
}

RTSCamera::~RTSCamera(void)
{
    shape->Release();
    pivot->Release();

    pivot = NULL;
    shape = NULL;
}

void RTSCamera::StartingPosition(Camera& camera)
{
    pivot->SetPosition(camera.GetPosition(true), true);
}

void RTSCamera::Update(Window& window, Camera& camera)
{
    Vec3 velocity = Vec3();
    Vec3 currentVelocity = pivot->GetVelocity();
    Vec3 finalVelocity = Vec3();

    if(window.KeyDown(Key::W))
          velocity.z++;

    velocity *= 20;
    velocity = Transform::Vector(velocity, &camera, NULL);

    finalVelocity = (velocity - currentVelocity) * 60;

    if(finalVelocity.Length() > 0)
         pivot->AddForce(velocity);

     camera.SetPosition(pivot->GetPosition(true), true);
}

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.

×
×
  • Create New...