Okay, first off let me point out that I'm already using setUserIndex for something important. Now I need save something else just as important. There is setUserPointer but it is a void. I need another way to save integers.
So for each rigid body I'm currently saving a single integer using setUserIndex, but I need to save more integers. How do you recommend I go about this?
(edit: in-case you need to see the project, https://github.com/Pottus/ColAndreas)
setUserIndex alternative?
-
- Posts: 51
- Joined: Tue Dec 11, 2012 9:59 pm
Re: setUserIndex alternative?
make a struct that contains the integers's you'd like to save and store that instead? (or actually user pointer instead... or keep an array of those structs and use the int as an index into that struct?)
setUserPointer works exactly the same as index... so I assume you mean like setUserIndex would be 0 if unused...
setUserPointer works exactly the same as index... so I assume you mean like setUserIndex would be 0 if unused...
-
- Posts: 15
- Joined: Mon Aug 10, 2015 10:18 pm
Re: setUserIndex alternative?
No it doesn't.d3x0r wrote:setUserPointer works exactly the same as index... so I assume you mean like setUserIndex would be 0 if unused...
setUserIndex stores integers.
setUserPointer stores void pointers.
setUserIndex is only capable of storing one integer per rigid body. I need to store more than one integer.
-
- Posts: 51
- Joined: Tue Dec 11, 2012 9:59 pm
Re: setUserIndex alternative?
struct s {Crayder wrote:No it doesn't.d3x0r wrote:setUserPointer works exactly the same as index... so I assume you mean like setUserIndex would be 0 if unused...
setUserIndex stores integers.
setUserPointer stores void pointers.
setUserIndex is only capable of storing one integer per rigid body. I need to store more than one integer.
int one_integer;
int more_than_one_integer;
}
s *info = new( s );
setUserPointer( s );
-
- Posts: 51
- Joined: Tue Dec 11, 2012 9:59 pm
Re: setUserIndex alternative?
I mean that it work exactly the same in that if you don't setUserIndex to anything getUserIndex will be 0... same if you don't setUserPointer, getUserPointer will of course be null.
-
- Posts: 15
- Joined: Mon Aug 10, 2015 10:18 pm
Re: setUserIndex alternative?
I'm sorry but I'm not very pro on C++. Can you go a little more in depth on how to do it with examples? Perhaps with an example on how to apply it and get it from a btRigidBody?d3x0r wrote:I mean that it work exactly the same in that if you don't setUserIndex to anything getUserIndex will be 0... same if you don't setUserPointer, getUserPointer will of course be null.
-
- Posts: 51
- Joined: Tue Dec 11, 2012 9:59 pm
Re: setUserIndex alternative?
1) there's no difference in C++ between a struct and a class except the default protection... struct is public: and class is private: by default. structs can have methods etc just like a class.Crayder wrote:I'm sorry but I'm not very pro on C++. Can you go a little more in depth on how to do it with examples? Perhaps with an example on how to apply it and get it from a btRigidBody?d3x0r wrote:I mean that it work exactly the same in that if you don't setUserIndex to anything getUserIndex will be 0... same if you don't setUserPointer, getUserPointer will of course be null.
the same way you set and get the index? but subst Index for Pointer and an address of a structure containing multiple values instead of a single value?
Code: Select all
// define a struct/class somewhere
struct your_values {
int a, b, c;
double e, f, g;
your_values( int _a, int _b ) { a = _a; b = _b; }
};
Code: Select all
btRigitBody* rb; // assume you can initialize this so it's not NULL or invalid.
void f() {
your_values *vals = new your_values( 1, 3 );
rb->setUserPointer( vals );
}
Code: Select all
// later get the value back
your_values *vals = (your_values*)rb->getUserPointer();
//though I guess the current standard looks more like
your_vals *vals = static_cast<your_values*>rb->getUserPointer();
Code: Select all
rb->setUserIndex( 1 );
//and later
int val = rb->getUserIndex();
Code: Select all
FILE *file = fopen( "some file for fun.txt", "wb" );
rb->setUserIndex( (int)file ) );
// and then later ....
FILE *file = (FILE*)rb->getUserIndex();
But either way you have to cast the result out.
I'm no good in C++ either; other than I know the basics of inheritance, protections, overloaded functions etc... which is why I don't really know why one would use static_cast<whatever> instead of just (whatever*).
-------
if this didn't give you an answer you'll have to ask more specific questions.