I'm using BulletPhysics in C++.
I would like to know if there is a way to avoid collision for an object when I want?
I'm trying to create a platformer and I want my character to be able to pass through a platform (by holding down the down button). I've thought about using ray cast to manage its position but it doesn't seems for me to be a good way; it would be better if I could access the physics response and choose whether or not to apply it to my object, but I don't know if this is possible.
(If you have a solution without code it's ok for me, I'm just making some research, I haven't started development).
Thank you in advance.
I found a solution to my problem.
To be able to cross a platform (by holding down the down button), you have to know if the character is on a platform. To do this, you have to put a box (which listens to all object that collide with it) and if it collides with a platform, get a pointer of the platform and call the method void setIgnoreCollisionCheck btCollisionObject * co, bool ignoreCollisionCheck) on the character's btCollisionObject.
Related
I am new to Unreal (switched from Unity) and still have some troubles understanding the main concepts, in this case how to access other objects and their components via c++ scriptig. I am using UE5 (but I guess solutions for UE4 should also work fine).
My Project looks as followed:
In my scene I have an "Target" Actor (Blueprintclass) that has a self written c++ "movement" component with some public function to update its position.
More over I have an "Experiment" BP Actor that has a "TrialProcedure" c++ component attached.
Here is what I want to do: I want to run the Target's movent component's update position function from this Actor's component.
I guess once I can access the Target Actor, I can use GetComponentByClass() to access the component I need and than run it's method. But how do I get access to that other actor without using blueprints? The Actor is already there so I don't want to spawn it from code.
Thanks in advance!
That is a sub-optimal solution. Use a collision and get the Other Actor, then try to cast it to your desired class if it's a collision event. If it fails, don't do anything but if it doesn't, pull a pin from that and execute your functions.
A better alternative to your current solution would be to use the Get All Actors of Class function if you only have a single target. Just use the Get (a copy) node and you'll have your target blueprint. There's a C++ version of the function as well. If you have more than one file, then you'll have to check stuff.
I've written a program based on an empty Win32 console app in VS2008 running on Win7 64bit. The program is entirely menu based spawning from a main.cpp which only calls external functions that lead to other interfaces based on the users needs (e.g. cashier, inventory, report, etc...). What I would love to do is provide a new console window for each interface.
Ideally it would close the main menu upon invoking any other interfaces and so on as the user progresses through its functions, including reopening the main menu when necessary.
The basis for doing it this way is that I'm starting a new semester next week diving deeper in OOP with C++ and I wanted to go over my text and complete the capstone project which progresses with the topics to ensure that I have all the basics down pat. As much as I would love to do this the smartest-easiest way, it's best if I stick to the limited knowledge presented in the book which only hints at STL and speaks nothing of additional libraries like boost.
I, of course, have searched on SO and elsewhere looking for the solution. I have found answers, most of them falling outside of my tight requirements, some dealing with building a console window from scratch. While from-scratch seems the most promising, it seemed to be dealing with those not using a robust IDE like VS and I don't know if it will cause more conflict than it's worth, or if it can even be used in multiplicity. The majority, however, left me with the impression it isn't possible. The one exception to this was linking a console to a process. This is what I hope is in my future!
What brought me to this was the need to present a clean look at each turn of events. At first I was fooling around with trying to clear the screen with a basic function like void clearScreen(int lines); but this will always clear from the bottom. So, if I clear the screen before the next interface it's still at the bottom. If I clear it then accept input, the prompt is still at the bottom.
In case it hasn't been clear up to this point. My question is:
Is it possible, within reason, to produce multiple console windows which are tied to processes, or is there an easy way which I do not know to manipulate the scrolling of the main console window?
Even though I "need" to stay within the confines of the baby-step process of traditional learning, I would love to hear any input aside from switching the app type.
This is more of an OCD issue than a requirement of the task, so if the effort isn't worth the benefit that's okay too.
There is no portable way of moving the cursor around the console window - in Unix/Linux, you can send terminal codes for that, in Windows I have no idea.
What would work cross-platform, but be terribly slow and not too nice, would be:
read your input character-by-character
remember where on the screen the next character should appear
redraw the whole screen after each key press
If you want to do better, you must turn to platform-specific solutions, or find a library which would do it for you (like ncurses in the Unix world), but I don't know if any of these fit in your requirements.
You can set the cursor-position on Windows using SetConsoleCursorPosition.
Since you were saying something about VS, I assume restricting yourself to Windows isn't a problem. If so, you can use the Windows API for this.
Other than that, ncurses seems to be at least partially ported to most common platforms.
If you were looking for a way to do this in standard C++ - it doesn't exist. C++ doesn't require the platform it's running on to even have a console, so there are no console manipulation functions.
Both aren't that hard to use, but if this is really just some student thingy where you expect to learn something useful you probably shouldn't bother. Console manipulation isn't something you'll have or want to do very often.
Although it may not have been clear in my original question, I was looking for a solution to be used in a console window. Ideally the solution would have been operable on at least Linux and Windows because any programs I write for school must be compiled on each. This wasn't an assignment but it's obviously advantageous to learn things that are usable there as well.
Here's what I found ...Solution thanks to Tim Wei
void clearScreen()
{
#ifdef _WIN32
system("cls");
#else
system("clear");
#endif
}
This, as simple as it is, was exactly what I was looking for. The function clears the screen and puts the cursor at the top of the console window providing a way to provide static headers or titles with changing data tables. It also allows for simple text based animations - if you like that sort of thing. It made a significant difference in the look, feel and consistency in my console applications this semester!
I'm looking for suggestion on how to handle this situation as anything I've thought of thus far does not work.
I'm working on an RPG game and am currently developing the graphical system. My graphics system consists of a series of ScreenStacks which are arranged in a particular order and then drawn.
A ScreenStack is basically just a collection of related Screens, along with a unique id and a draw order.
i.e.
class ScreenStack
{
//Constructors, getters/setters etc.
private:
std::string StackName;
int DrawPriority;
int UID;
bool Valid;
bool DrawStack;
bool UpdateStack;
bool SendInputs;
bool DeleteStack;
std::vector<screen_ptr> OwnedScreens; //screen_ptr is a shared_ptr around a Screen object
};
A screen is a simple graphical layer responsible for visualizing some part of the game, for example there's a screen for showing the player inventory, party overview, party status in battle, enemy party, etc.
I have a screen manager that is responsible for storing the various functions for creating screen stacks (i.e. a function to create a battle stack will make a screen for the player party, the enemy party, the attack animation screen, the background, and the user interface). Each of the various screen stack creation functions needs a different set of paramters to construct it. What I'm doing now is manually adding in stack creation functions to the screen manager on an as needed basis. For instance, right now the screen manager has a function for creating the title screen stack, the start menu stack, the battle stack, the overworld stack, the tilemap stack etc.
This works, but is cumbersome and cluttered. What I'd like to be able to do is have files external from the screen manager be able to register stack creation functions with the screen manager and then I can just look up the screen creation function instead of having to add a new function to the screen manager for each stack I need to create.
I initially tried adding an unordered_map<std::string, StackCreationFunction> with StackCreationFunction being typedef'd as
boost::function<ScreenStack (Engine& engine, ScreenManager& manager, const std::string screenName, const int StackID, const std::vector<std::string>& TryToCopyScreens, ...)>
... was from cstdargs. The idea was that each ScreenStack would add it's own StackCreationFunction to this map. This doesn't work however as boost::function is invalid with ...
So essentially what I'm trying to do is allow external files/screens be able to register their own creation functions (that has variable arguments) with the screenmanager, and Ideally be able to do this at compile time/immediately after starting. This feels like it should be possible with the preprocessor, but I'm unsure how to do it. I'm pretty stuck here, and I really would like a better solution then adding many stack creator functions to the screen manager and cluttering it up.
Any suggestions/a better solution would be greatly appreciated, and I can provide more details if the above was not clear enough
Thanks
Each of the various screen stack creation functions needs a different set of paramters to construct it.
I think that's the problem here, and you need to think of an abstraction here to make your map work. After all, how are these extra arguments actually provided by the calling code? When the calling code knows which class is instantiated and can provide the arguments, you don't need the map. When not, the map is of no use, since you can't tell which arguments to provide to the stack creation function.
The most likely solution is to boost::bind away all arguments of your StackCreatorFunction that would normally go into the ... arguments and register this bound version of your function at the unordered map, which can be freed of the ....
I would suggest that rather than having something external register into your system think about having your system call the external entity. In this case your system would locate and load a series of plugins that have specific entry points. You will need to create your variable length argument list using some convential container; either an array or data structure.
I'm not sure if that answers your question, but if your concern is to call various functions of different signatures from an interpreter-like code, you could (under GNU/Linux at least) use the LibFFI (a library for foreign function interface) for that.
Sorry for the rather vague title, but it seemed befitting of a similarly vague question, though hopefully succinct enough that somebody will be able to answer it. I have spent a decent amount of time working on the framework for a 2D side-scrolling game in SDL, and now that I am comfortable with the library and have a working prototype, I'm looking to integrate the Box2D physics library into my game. Now, I didn't just dive in head first and actually took the time to compile the library on my system (obviously), study the Testbed application, create a few of my own to get the hang of it all. And yet, I'm still unable to figure out how exactly to integrate it into my existing game structure. Below is a sample of my source for the game "engine," if I may be so bold:
CMain.cpp
// Constructor. Initialize the screen display surface and
// let the application know that we are running.
CMain::CMain(){
displaySurface = NULL;
isRunning = true;
}
// Init function, hooks SDL libraries, configures the display
// surface, window and all pre-runtime environment parts.
int CMain::OnExecute(){
if(OnInit() == false){
return -1;
}
// Event checking, game loop and render loop.
SDL_Event Event;
while(isRunning){
while(SDL_PollEvent(&Event)){
OnEvent(&Event);
}
OnLoop();
OnRender();
}
// Cleanup, called when the application is no longer running,
// handles the removal of all loaded resources from memory.
OnCleanup();
return 0;
}
int main(int argc, char* argv[]){
CMain digIt;
return digIt.OnExecute();
}
As you can see this takes care of the crucial game loop functions. I didn't think the full code of the various helper functions was necessary for the context of the question, but if it would be helpful just say so and I'd be glad to post it. So, my question is this:
Being familiar with the structure of the Box2D world and how it is initialized, stepped and everything, how do I now integrate that into this existing game structure? Do I want my entire CMain class to inherit from b2World? (i.e. class CMain : b2World{}) is there some other way to create the world so that it is globally accessible without committing a cardinal sin of good coding practice? For instance, I tried to declare a b2World* pointer in the CMain header and then pass that around to the subsequent functions to do with it what they had to do but that lead to a great many null pointer exceptions. Any advice you could give, or sample code if at all possible, will be incredibly appreciated!
I would not suggest that your CMain class derives from the b2world, since it definitely is not a is-a relation but rather a has-a. I cannot tell if it is the perfect solution, since I do not know your overall architecture, but it seems like a good place fot the Singleton pattern.
I suggest that you create a class implementing the singleton pattern which holds the central instance of b2World, like CPhysicsService. The instance is taked with stepping the world and for creation of new bodies. Because of the singleton, the instance of the class can be retrieved anywhere you need it.
I also had this issue while making an extension for the Gamebryo engine. But the engine was heavily built on services anyway, so the creation of a Box2D service was the obvious way to go.
I hope this was somehow useful.
Greetings!
I am currently attempting to extend the functionality of the Magic Mouse. To do this, I am hoping to write a kext that intercepts events from the multitouch driver, AppleMultitouchDriver.kext, interprets them, and either dispatches new events or forwards the actual event. This approach is similar to the approach used by DoubleCommand.
I have already created a small test kext that intercepts the mouse events (click, motion, etc) as that will be needed also.
The problem I am having now is that I am unable to intercept the events from the AppleMultitouchDevice and/or AppleMultitouchHIDEventDriver objects because there is no class definition for them. I need to be able to reassign the pointer to the callback function as I do in the mouse interceptor and as is done in DoubleCommand. As far as I know, this means I need to reconstruct the AppleMultitouchDevice class. I already am able to get a reference to the instance of the AppleMultitouchDevice object, so I just need to be able to cast it and use it.
Now that you have the background, here are my direct questions:
What methods do I need to use in order to reverse engineer the kext or reconstruct the classes in question?
What programs are available that will assist me in this effort?
Are there any tutorials or e-books that focus on this particular topic that you know of?
Is it possible for me to reassign the callback pointer without actually reconstructing the entire class?
Anything else I may have missed as I am so very new to this.
Thanks in advance for any advice or assistance!!
Could this be of any help?
FingerMgMt
I've managed to find what I needed. Now all it will take is time and effort. :)