Constructing a KinematicPlatform gives me r6025 - pure virtual function call error at runtime:
[cpp]
KinematicPlatform::KinematicPlatform(const btVector3& size, const btTransform& transform, btDynamicsWorld& dynamicsWorld, std::function<btTransform(double)> transformFunction) :
Platform(size, transform, dynamicsWorld),
baseTransform(transform),
transformFunction(transformFunction),
t(0)
{}
[/cpp]
Platform::Platform (the class is derived from Platform):
[cpp]
Platform::Platform(const btVector3& size, const btTransform& transform, btDynamicsWorld& dynamicsWorld) :
size(size),
shape(size / 2),
rigidBody(getCI(shape, transform))
{
dynamicsWorld.addRigidBody(&rigidBody);
}
[/cpp]
The error seems to vanish when I comment out the line "dynamicsWorld.addRigidBody(&rigidBody);", but I need the rigid body to be added to the world.
edit: No wait, somehow the error occurs in btDiscreteDynamicsWorld::stepSimulation. For some reason, adding the body to the world through the base constructor makes it error.
Is getCI a pure virtual function? Don't call virtual functions in constructors (some compilers also warn about that, yours might not or might simply not be configured to do so).
The vtable will not yet point to the correct entry. Platform will set the functions to its "implementations" (which in the pure virtual function case usually points to a function printing an error and then terminates/crashes), only when the constructor of the Subclass is reached, it will set the correct entry (which might still not be correct though if it's actually an instance of the Subsubclass type).
If the Subclass constructor would set the vtable before invoking the Baseclass constructor, then it would simply be overwritten, so you don't have much options other than not doing that.
A possible solution is to pass the return-value of Subclass::getCI(...) in the Subclass constructor to the Baseclass constructor.
[QUOTE=ZeekyHBomb;41902863]Is getCI a pure virtual function? Don't call virtual functions in constructors (some compilers also warn about that, yours might not or might simply not be configured to do so).
The vtable will not yet point to the correct entry. Platform will set the functions to its "implementations" (which in the pure virtual function case usually points to a function printing an error and then terminates/crashes), only when the constructor of the Subclass is reached, it will set the correct entry (which might still not be correct though if it's actually an instance of the Subsubclass type).
If the Subclass constructor would set the vtable before invoking the Baseclass constructor, then it would simply be overwritten, so you don't have much options other than not doing that.
A possible solution is to pass the return-value of Subclass::getCI(...) in the Subclass constructor to the Baseclass constructor.[/QUOTE]
getCI isn't even a member function, it's a regular function. Also, see my edit. The error doesn't seem to occur in the constructor, it occurs when I simulate the world. Somehow, the rigid body must be constructed or added to the world differently when added through the chain. I don't see how that can happen though.
The only thing I could think of then is that transform is not fully constructed and somehow copied in getCI (directly or indirectly) or that it's a temporary and it's stored there and this is just the result of undefined behavior.
If that's not it, try to compare the working and non-working versions in a debugger.
[QUOTE=ZeekyHBomb;41903115]The only thing I could think of then is that transform is not fully constructed and somehow copied in getCI (directly or indirectly) or that it's a temporary and it's stored there and this is just the result of undefined behavior.
If that's not it, try to compare the working and non-working versions in a debugger.[/QUOTE]
It is fully constructed, I give the exact same value of transform for a Platform and KinematicPlatform. The Platform works, the KinematicPlatform doesn't. Will try to debug it.
I think I tracked it down to this line in Bullet itself:
[cpp]
...
void btCollisionWorld::updateSingleAabb(btCollisionObject* colObj)
{
btVector3 minAabb,maxAabb;
------->colObj->getCollisionShape()->getAabb(colObj->getWorldTransform(), minAabb,maxAabb);
//need to increase the aabb for contact thresholds
btVector3 contactThreshold(gContactBreakingThreshold,gContactBreakingThreshold,gContactBreakingThreshold);
minAabb -= contactThreshold;
maxAabb += contactThreshold;
...
[/cpp]
So it seems like one of those method calls are done on an object where that method is purely virtual? How do I find out which one it is?
edit: Never mind, I think I figured that out. The colObj has a __vfptr where getCollisionShape isn't included. Surely this must mean that the method is purely virtual on that type? And that should mean that it somehow has a btCollisionObject instead of a btRigidBody. That's really strange, considering I never ever construct a btCollisionObject, and I don't even know if that's possible. Maybe it has something to do with the fact that the btRigidBody is a regular value member that resides in the base class, Platform?
Maybe btRigidBody inherits btCollisionObject? This would then just be the result of an upcast, which is perfectly save. If btRigidBody defines getCollisionShape it should be fine though (and it has to, otherwise you couldn't store it as a value).
Somehow it does not get constructed properly though. I'd suggest breaking at the constructor entry and stepping through and comparing the working and non-working versions like that.
[QUOTE=ZeekyHBomb;41903319]Maybe btRigidBody inherits btCollisionObject? This would then just be the result of an upcast, which is perfectly save. If btRigidBody defines getCollisionShape it should be fine though (and it has to, otherwise you couldn't store it as a value).
Somehow it does not get constructed properly though. I'd suggest breaking at the constructor entry and stepping through and comparing the working and non-working versions like that.[/QUOTE]
It does inherit from that. I know how to make breakpoints, but what do you mean with stepping through? Because I don't think I can make breakpoints in Bullet code.
And isn't the point of virtual methods that despite an upcast, the correct one will be called?
That's what I meant by perfectly save. I think the issue must lie somewhere in the construction.
Stepping means advancing one instruction. That'd be the step (or just s) command in gdb.
[QUOTE=ZeekyHBomb;41903518]That's what I meant by perfectly save. I think the issue must lie somewhere in the construction.
Stepping means advancing one instruction. That'd be the step (or just s) command in gdb.[/QUOTE]
I think I found the appropriate features in Visual C++ for that. But I'm unfortunately not really sure how to see if anything goes wrong during construction. When I stepped through it it was just a load of vector and quaternion assignments (and I stepped into each one) and a lot of rigid body property assignments. How am I supposed to know where it goes wrong? It seemed to follow everything perfectly.
[editline]20th August 2013[/editline]
I just decided to try a compositional approach to the problem, since I wasn't getting anywhere with the problem. Now another question: I want to have an optional transform function as parameter. I solve this by using a pointer to an std::function. Is there a quick way to pass a pointer to an std::function with a lambda?
I thought you'd compare it to the working version. Although since the vtable stuff is "hidden" I'm not sure if it'd turn up anything interesting.
You could perhaps try a memory-debugging tool like valgrind (Capsup, a couple of pages back, used one available for Windows), but I'm also not sure if that'd help.
Perhaps try on the Bulletphysics forum or IRC.
boost::optional? Otherwise you have to assign it to an lvalue first before you can take the address of it.
[QUOTE=ZeekyHBomb;41903831]I thought you'd compare it to the working version. Although since the vtable stuff is "hidden" I'm not sure if it'd turn up anything interesting.
You could perhaps try a memory-debugging tool like valgrind (Capsup, a couple of pages back, used one available for Windows), but I'm also not sure if that'd help.
Perhaps try on the Bulletphysics forum or IRC.
boost::optional? Otherwise you have to assign it to an lvalue first before you can take the address of it.[/QUOTE]
Alright, I should probably start using boost right now, the benefits are probably bigger than the annoyances with using yet another library.
I'm still trying to trudge through the headfirst c# book, but when it tells me to make a int variable private, before it told me to use that variable outside the class. It gave me two methods to work around it, but it still calculates the total cost wrong.
[code]namespace DinnerParty
{
public partial class Form1 : Form
{
DinnerParty dinnerParty;
public Form1()
{
InitializeComponent();
dinnerParty = new DinnerParty();
dinnerParty.SetHealthyOption(false);
dinnerParty.CalculateCostOfDecorations(fancyBox.Checked);
dinnerParty.SetHealthyOption(healthyOption.Checked);
}
private void DisplayDinnerPartyCost ()
{
decimal Cost = dinnerParty.CalculateCost(healthyOption.Checked);
costLabel.Text = Cost.ToString("c");
}
private void NumberOfPeople_ValueChanged(object sender, EventArgs e)
{
dinnerParty.SetPartyOptions((int)NumberOfPeople1.Value, fancyBox.Checked);
DisplayDinnerPartyCost();
}
private void healthyOption_CheckedChanged(object sender, EventArgs e)
{
dinnerParty.SetHealthyOption(healthyOption.Checked);
DisplayDinnerPartyCost();
}
private void fancyDecoration_CheckedChanged(object sender, EventArgs e)
{
dinnerParty.GetNumberOfPeople();
dinnerParty.CalculateCostOfDecorations(fancyBox.Checked);
DisplayDinnerPartyCost();
}
}
}[/code]
[code]using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace DinnerParty
{
class DinnerParty
{
private int NumberOfPeople;
public const int CostOfFoodPerPerson = 25;
public decimal CostOfBeveragesPerPerson;
public decimal CostOfDecorations;
public void SetHealthyOption(bool healthyOption)
{
if (healthyOption)
{
CostOfBeveragesPerPerson = 5.00M;
}
else
{
CostOfBeveragesPerPerson = 20.00M;
}
}
public decimal CalculateCost(bool healthyOption)
{
decimal totalCost = CostOfBeveragesPerPerson + CostOfFoodPerPerson * NumberOfPeople;
if (healthyOption)
{
return totalCost * .95M;
}
else
{
return totalCost;
}
}
public void CalculateCostOfDecorations(bool fancy)
{
if (fancy)
{
CostOfDecorations = (NumberOfPeople * 15.00M) + 50M;
}
else
{
CostOfDecorations = (NumberOfPeople * 7.50M) + 30M;
}
}
public void SetPartyOptions(int people, bool fancy)
{
NumberOfPeople = people;
CalculateCostOfDecorations(fancy);
}
public int GetNumberOfPeople()
{
return NumberOfPeople;
}
}
}[/code]
Going back through the book to relearn everything I forgot. =/
Wrong how?
Perhaps because you're only adding a single beverage?
Fancy decorations, price total doesn't add that in.
So then add it to the total.
Let's say I want to make a simple game [I]with multiplayer[/I], let it be X-O.
What are the steps of network programming here? I mean not exactly how it's done, but what I should consider in networking part so I won't have any problems later.
[sp]I'm afraid you can just send me to google, though.[/sp]
Tackling networking at a low level would be opening sockets and sending, receiving and interpreting a bunch of bytes.
Depending on the programming language you use there might be higher level abstractions on various levels.
On a high level abstraction you might be able to mark the fields of a class that need to be networked and they'll be automatically synchronized when they change.
On a lower lever there are a few things to consider:
There are two major layer 4 protocols in use: TCP and UDP.
The former provides some guarantees that make it slower, but more reliable.
The latter has less overhead, but also is unreliable.
For real-time stuff you usually build a reliability layer on top of UDP, but I guess otherwise you can just use TCP.
For todays world you should allow for both IPv4 and IPv6 as layer 3. That should be rather painless to implement.
On top of that you just have to think about how to structure your messages. Try not to use strings for everything, where you can use enumerations and choose the smallest fitting type.
Packets usually start with a type identifier, which determines how the rest of the packet should be interpreted. Anything beyond that depends on the data you want to send.
I'm not sure if you need this for TCP, but at least for UDP you also need a way to determine the size of a packet. Different types might have different sizes, or there might even be packets of variable length.
You can either append some packet-end token or also put the size of the packet at the start, next to the type identifier.
A common principle for games is to not trust the client. If for a shooter for example you'd let the client calculate the damage done to his opponent and use that information on the server (didn't Crysis do this?) then the client could easily claim he's done 1000 damage.
Instead let the client send information about his actions (rotation in direction X, fire my weapon), then the server looks what that would do (movement currently not restricted, weapon ready to fire) and thus limit the false information the client can give.
This doesn't prevent the client from using an aimbot, but it limits their ability to cheat.
[editline]21st August 2013[/editline]
And in real-time stuff you also need to work against networking delay.
There's stuff like client-side prediction and server-side lag-compensation (at least that's how it's called in Source).
Client-side prediction simply means that the client simulates his own world while it doesn't get data from the server. Once it gets new data, it'll extrapolate the data to compensate for the delay (since the data will be a bit older) and interpolate between the current state and the extrapolated state.
The server-side lag-compensation also considered that the data from the client is old, so for example if the server receives the information that a player shot a gun, that actually happened in the past, so it needs to move everything back in time a bit to see if the bullet, that was fired in the past, hit something.
And for the server to update its state it needs to extrapolate the data as well.
Having a bit of a problem with using a seperate VBO for colors in OpenGL. It is rendering the box correctly, but for some reason the color isn't being passed to the shader.
[CODE]
public Mesh() {
shaderProgram = new ShaderProgram();
shaderProgram.compileShader("default_vertex.glsl", GL_VERTEX_SHADER);
shaderProgram.compileShader("default_fragment.glsl", GL_FRAGMENT_SHADER);
vertices = new float[] {
-.5f, -.5f, 0f,
-.5f, .5f, 0f,
.5f, -.5f, 0f,
.5f, .5f, 0f
};
colors = new float[] {
1f, 0f, 0f,
0f, 1f, 0f,
0f, 0f, 1f,
0f, 0f, 1f
};
FloatBuffer vertexPositions = BufferUtils.createFloatBuffer(vertices.length);
vertexPositions.put(vertices);
vertexPositions.flip();
FloatBuffer vertexColors = BufferUtils.createFloatBuffer(colors.length);
vertexColors.put(colors);
vertexColors.flip();
// Generate the vao first and bind it so it can contain the vbos.
vaoID = glGenVertexArrays();
glBindVertexArray(vaoID);
// Vertex positions
vboPosID = glGenBuffers();
glBindBuffer(GL_ARRAY_BUFFER, vboPosID);
glBufferData(GL_ARRAY_BUFFER, vertexPositions, GL_STATIC_DRAW);
glEnableVertexAttribArray(0);
glVertexAttribPointer(0, 3, GL_FLOAT, false, 0, 0);
// Vertex colors
vboColID = glGenBuffers();
glBindBuffer(GL_ARRAY_BUFFER, vboColID);
glBufferData(GL_ARRAY_BUFFER, vertexColors, GL_STATIC_DRAW);
glEnableVertexAttribArray(1);
glVertexAttribPointer(1, 3, GL_FLOAT, false, 0, 0);
// Unbind the vertex array, It has all the data we need for rendering now.
// The vertex buffer object does not need to be bound anymore.
glBindVertexArray(0);
glBindBuffer(GL_ARRAY_BUFFER, 0);
[/CODE]
Here are my shaders:
Vertex shader:
[CODE]
#version 330
layout (location = 0) in vec3 inPosition;
layout (location = 1) in vec3 inColor;
out vec3 color;
void main(){
color = inColor;
gl_Position = vec4(inPosition, 1.0);
}
[/CODE]
Fragment shader:
[CODE]#version 330
in vec3 color;
void main(){
gl_FragColor = vec4(color, 1.0);
//gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);
}[/CODE]
EDIT:
Found out that the vertex shader wasn't being compiled and it was using the default. I fixed it.
[QUOTE=suXin;41914792]Let's say I want to make a simple game [I]with multiplayer[/I], let it be X-O.
What are the steps of network programming here? I mean not exactly how it's done, but what I should consider in networking part so I won't have any problems later.
[sp]I'm afraid you can just send me to google, though.[/sp][/QUOTE]
ZeekyHBomb provided a really good explanation. SFML provides a really simple interface for working with TCP/UDP packets. I recently added multiplayer to one of my games and it wasn't crazy difficult. Making that multiplayer work nicely (have good reliability and lag compensation) is the really hard part.
Okay, this is actually mostly a math question.
Say I have a hover car that I need to hover a certain distance off of the ground, and try to stay at that height as stably as possible.
What force would get the car to behave that way?
We know the vertical velocity of the car, and its displacement from the desired height. We also know the force of gravity on the car:
[img]http://s22.postimg.org/qbgvqc9pt/hover.png[/img]
There's obviously more than one way to solve this, but can anybody think of a simple, elegant solution?
Problems I'm trying to avoid are silly oscillations and other instability. I'm thinking about using a [url=http://en.wikipedia.org/wiki/Damping#Example:_mass.E2.80.93spring.E2.80.93damper]damped spring[/url], but can anyone think of a better way off the top of their head?
EDIT:
Never mind. The damped spring worked perfectly. Nothing to see here.
[QUOTE=Smashmaster;41921164]Okay, this is actually mostly a math question.
Say I have a hover car that I need to hover a certain distance off of the ground, and try to stay at that height as stably as possible.
What force would get the car to behave that way?
We know the vertical velocity of the car, and its displacement from the desired height. We also know the force of gravity on the car:
[img]http://s22.postimg.org/qbgvqc9pt/hover.png[/img]
There's obviously more than one way to solve this, but can anybody think of a simple, elegant solution?
Problems I'm trying to avoid are silly oscillations and other instability. I'm thinking about using a [url=http://en.wikipedia.org/wiki/Damping#Example:_mass.E2.80.93spring.E2.80.93damper]damped spring[/url], but can anyone think of a better way off the top of their head?[/QUOTE]
I'm thinking back to my Garry's Mod days for this;
[code]force = (targetHeight - currentHeight) * mass * some_factor - velocity * some_other_factor[/code]
In this case, 'velocity' is the velocity in the direction you wish to apply your force (so probably the Y axis.)
'some_factor' is a multiplier that affects the magnitude of the correction force applied.
'some_other_factor' is a multiplier that affects the damping force applied, this should generally be lower than 'some_factor'.
You'll have to play with the numbers a bit, but I think that should work.
[QUOTE=Chris220;41921251]I'm thinking back to my Garry's Mod days for this;
[code]force = (targetHeight - currentHeight) * mass * some_factor - velocity * some_other_factor[/code]
In this case, 'velocity' is the velocity in the direction you wish to apply your force (so probably the Y axis.)
'some_factor' is a multiplier that affects the magnitude of the correction force applied.
'some_other_factor' is a multiplier that affects the damping force applied, this should generally be lower than 'some_factor'.
You'll have to play with the numbers a bit, but I think that should work.[/QUOTE]
Yup, that's basically what I ended up doing. The damped spring works perfectly. However, it also needs an anti-gravity force or else it will never stop oscillating:
[cpp]
float antiGrav = body.m_mass * -world.getGravity().y;
float spring = 10f*(hoverHeight - groundDist);
float dampening = -2f*body.getLinearVelocity().y;
float hoverForce = spring + antiGrav + dampening;
body.applyForceToCenter(new Vec2(0f, hoverForce));
[/cpp]
Hey guys, need a little help with an engine i'm working on.
Iv'e made a clock class, I need however a solution that can call a function at intervals different from the clock's interval. for instance, call a method every second from a timer that elapses every 12 milliseconds. I want to be able to schedule events from any class from which the clock instance is visible.
the timer works great for drawing, and the main game logic, and animation but if I want something to occur at a longer interval, i'm forced to hard-code it so to speak.
My proposed solution;
- Create a 'Job' struct containing the method to be called, the time to be called and whether it should reoccur.
- Add a 'Schedule Action' method to the clock, this is passed a method, time and reoccur Boolean, and a Job is created. This job is added to a list of jobs ordered by time until execution. on each clock 'elapsed' event, a variable representing the time until the first job in the list is updated, if this is < 0, call the method and remove from list, update the timeTillNextJob.
- if the event should reoccur, reschedule it.
is this a valid solution?, if so, i'm not very experienced with delegates, how can ANY method be passed (with any/all parameters respectively).
can anyone give an example of the job struct? i can sort the rest hopefully myself, thanks.
What model/mesh formats support Normals, Animations and Tangents?
It seems like none exist.
Why not just generate tangents? I'm sure there are others that support normals and animations.
I'm honestly not too worried about tangents.
However, I'm still having trouble finding a non-bloated format that supports skeletal animation and normals.
[QUOTE=Lemmingz95;41922111]Hey guys, need a little help with an engine i'm working on.
Iv'e made a clock class, I need however a solution that can call a function at intervals different from the clock's interval. for instance, call a method every second from a timer that elapses every 12 milliseconds. I want to be able to schedule events from any class from which the clock instance is visible.
the timer works great for drawing, and the main game logic, and animation but if I want something to occur at a longer interval, i'm forced to hard-code it so to speak.
My proposed solution;
- Create a 'Job' struct containing the method to be called, the time to be called and whether it should reoccur.
- Add a 'Schedule Action' method to the clock, this is passed a method, time and reoccur Boolean, and a Job is created. This job is added to a list of jobs ordered by time until execution. on each clock 'elapsed' event, a variable representing the time until the first job in the list is updated, if this is < 0, call the method and remove from list, update the timeTillNextJob.
- if the event should reoccur, reschedule it.
is this a valid solution?, if so, i'm not very experienced with delegates, how can ANY method be passed (with any/all parameters respectively).
can anyone give an example of the job struct? i can sort the rest hopefully myself, thanks.[/QUOTE]
Sounds good.
I'm unsure if you can have(, or even want, I might have understood you incorrectly), variadic delegates.
Not your struct, but here's how you use delegates:
[code]delegate int IReturnInt();
delegate void ITakeInt(int i);
int foo;
int getFoo() { return foo }
void setFoo(int newFoo) { foo = newFoo }
IReturnInt intReturner = getFoo;
ITakeInt intTaker = setFoo;
intTaker(0);
intReturner(); //== 0[/code]
[QUOTE=Lemmingz95;41922111][...][/QUOTE]
If you don't want to have a global game time (problematic if you have long time persistent games), you can just add the remaining delay and delegate to the struct (and a flag for reoccurring events), then you can decrement the delay from the update method and call the delegate once that's complete.
The easiest way is probably to put them into a list, but you can skip a lot of the decrement operations if you have a sorted queue and decrement the delay by all earlier-completing ones when inserting, as you only have to process the next one each frame.
If the new element isn't the last you subtract its remaining delay from the following existing item.
If your language supports continuations (C# async for example): They work [B]very[/B] well with event queues like this. In C#'s case you'd have to write a (possibly empty) awaitable/awaiter struct to queue the callback though.
I have a question, but it's not that important.
Java (and most other languages, for that matter) will precompute stuff like this when you compile to bytecode:
[cpp]
double v = Math.sin(Math.PI/4.0);
...into:
double v = 0.70710678118;
[/cpp]
But let's say I have a method like this:
[cpp]
public static float sin(float a)
{
return (float)Math.sin(toRadians(a));
}
[/cpp]
Will Java be smart enough to precompute this if the input is constant? The method is static, so it can't be overridden. I don't see any reason it shouldn't precompute like so:
[cpp]
float v = sin(45f);
...into:
float v = .70710678118f;
[/cpp]
Basically, what are the rules for Java precomputation? How extreme can it be? Let's say I have a final or static method that computes PI out to a million binary places.
Hypothetically, if I were to actually run it in real time on one thread, it would take a few minutes.
But because pi is a constant, it doesn't use any information or objects that aren't known at compile time. Would Java precompute such a method?
[cpp]
/*
* Ultra-expensive million-place naive computation of pi. Computes many
* near-zero terms that end up getting truncated on summation.
*/
double pi = pi();
...into:
double pi = 3.14159265358979323846;
[/cpp]
I would test this myself, but I've got more important things to do than purposefully coding an algorithm that slowly computes pi.
Also, how do some other languages/compilers handle this?
[b]EDIT:[/b] Actually, since I got curious, I went and tested some stuff. Guess what this outputs:
[cpp]
public static void main(String[] args)
{
long t0 = 0, t1 = 0;
t0 = System.nanoTime();
Math.sin(Math.PI/4);
t1 = System.nanoTime();
System.out.println(t1 - t0);
}
[/cpp]
If you comment out Math.sin(), you get 0 nanoseconds. If you leave it in... you get 25000 nanoseconds or so, depending on your processor. So this is interesting. Java doesn't precompute ANY method, no matter if the inputs are constant, or if its output isn't being used. Maybe this is because I'm running the project from Netbeans? Would it be zero if I built and ran the .jar?
[b]EDIT 2:[/b] Nope, Java don't give a shit. You know what, never mind. I'll just optimize my code more carefully from now on.
Thank you for the replies, ill be sure to post progress. Yes I was thinking of variadic delegates, to sort of 'cover all bases' but ill leave it to the user to add their own.
And to tamschi, I do have global game time, but im looking into ways to shedule things on the fly, eg. when you click x, in two seconds call functions; x, y and z. repeat y and z every 2 seconds 5 times.
I could be missing something obvious, but i cant think of an easy way to do that with one game timer.
still, both helpful and i'm very thankful!
Sorry, you need to Log In to post a reply to this thread.