I wanted to know if anyone has idea how to do the following:
we have a 3D model of a character ..
Now I need to make, is that this "character" have interchangeable parts ...
For example, if you want to add a helmet or armor to the model, I guess I should replace the vertex of the torso or head vertex for the armor or helmet vertex.
That's where the problem comes, as I can know where "the part" starts and where finish and start another part? (in blender so I have separate the character in "groups", arm, foot, head, etc..
I think a possible solution:
i had thought to create an object for each "part" and load as separate models (arm on one side, head for the other and so) and handle all parts as "one model".
but I think it is not right... you can tell me what is the correct way ? tell me your experience in this case (if you know any tutorial on this subject. thanks!)
i Working in C ++ and OpenGL 3+ on Windows
For modeling using Blender.
Ive never done it from scratch in opengl but in unity what you do is, if you want for exemple a sword in your characters hand, you give the sword model the position and rotation of the bone that is in the characters hand, and the object(sword) will movea cordingly to the hand.
You can obviously do the same for armor, hair and all kinds of cosmetics.
If you want to change body parts like an arm or hand the prenciple is the same, you can for exemple use a tranparente texture for the part you want to switch and simple put the new hand as mentioned above.
Related
I am creating the demonstration of the algorithm. The issue I am facing is how to animate the algorithm step by step, so on timeout or on click the algorithm does one step and presents it on screen. I want the algorithm below to go one step (as indicated at the lines) at the time, so everytime the function is called it does just one step of the algorithm. The closest to the idea would be like debugging the algorithm - on every call it would go to the next "breakpoint" (step one, two, three in the code)
void MainWindow::animationStep()
{
// this as a whole goes all in one step - for now
QVector<QVector3D> mp = myView->points;
QVector2D p0(mp.back()); // in step one - highlight this point
mp.pop_back();
mp.pop_back();
while(!mp.empty()){
QVector2D pTemp(mp.back()); // in step two - highlight this point
mp.pop_back();
// in step three - draw this line
QGraphicsLineItem *line = myView->scene->addLine(p0.x(), p0.y(), pTemp.x(), pTemp.y(), QPen(Qt::blue, 3));
line->setZValue(-1);
// next step - continue
}
}
I have an idea to put every part in different function and execute them based on the global counter, but that seems to be unnecessarily complicated. Is there some easy way to do that?
I see two ways to accomplish an animated display of running your code.
The first option is to split the code up so that it is operated in steps on call backs. This will be pretty ugly. You may be able to use some sort of co-routine package to make it appear less ugly.
The second option is to no actually run the algorithm and display together. In this situation, when running the algorithm, you would record all the steps in a time based data structure, then have separate code that plays back that data structure to the display. The downside to this is that now the display code has no way to effect the algorithm as it runs.
I've searched my best on here in order to find the answer to my question but there's either no results or I'm not searching the right thing, but anyway...
The battleships game I need to create has to have: 1 Aircraft Carrier of length 5, 2 battleships of length 4, 3 destroyers of length 3 and 4 submarines of length 2.
I have a ship class which holds data such as the id, name, x, y and direction.
I then have a board class which then needs to instantiate all these ships. I'm doing this by making a vector of type Ship and pushing ship objects onto that.
However each ship objects needs to store all the x and y values of that ship and I'm stuck on how to do that. I wanted to post code but it's non functional and looks messy at the moment which is probably not beneficial to anyone. However if necessary I can write the skeleton again and post it up here.
Thanks in advance.
If you have x, y and direction then the points of the ship can be calculated from it's size
Each ship could just have a vector<Point> inside. Checking for hit could be then:
Point guess;
for (auto& ship : ships) {
for (auto& point : ship.points) {
if (point == guess)
// hit
}
}
That would make sense if you are aiming for a version where you need to hit the ship once in each of its parts.
The inner loop can also be easily changed to std::find, making it arguably more clear.
I am not sure how you are supposed to control a player character in Bullet. The methods that I read were to use the provided btKinematicCharacterController. I also saw methods that use btDynamicCharacterController from the demos. However, in the manual it is stated that kinematic controller has several outstanding issues. Is this still the preferred path? If so, are there any tutorials or documentations for this? All I found are snippets of code from the demo, and the usage of controllers with Ogre, which I do not use.
If this is not the path that should be tread, then someone point me to the correct solution. I am new to bullet and would like a straightforward, easy solution. What I currently have is hacked together bits of a btKinematicCharacterController.
This is the code I used to set up the controller:
playerShape = new btCapsuleShape(0.25, 1);
ghostObject= new btPairCachingGhostObject();
ghostObject->setWorldTransform(btTransform(btQuaternion(0,0,0,1),btVector3(0,20,0)));
physics.getWorld()->getPairCache()->setInternalGhostPairCallback(new btGhostPairCallback());
ghostObject->setCollisionShape(playerShape);
ghostObject->setCollisionFlags(btCollisionObject::CF_CHARACTER_OBJECT);
controller = new btKinematicCharacterController(ghostObject,playerShape,0.5);
physics.getWorld()->addCollisionObject(ghostObject,btBroadphaseProxy::CharacterFilter, btBroadphaseProxy::StaticFilter|btBroadphaseProxy::DefaultFilter);
physics.getWorld()->addAction(controller);
This is the code I use to access the controller's position:
trans = controller->getGhostObject()->getWorldTransform();
camPosition.z = trans.getOrigin().z();
camPosition.y = trans.getOrigin().y()+0.5;
camPosition.x = trans.getOrigin().x();
The way I control it is through setWalkDirection() and jump() (if canJump() is true).
The issue right now is that the character spazzes out a little, then drops through the static floor. Clearly this is not intended. Is this due to the lack of a rigid body? How does one integrate that?
Actually, now it just falls as it should, but then slowly sinks through the floor.
I have moved this line to be right after the dynamic world is created
physics.getWorld()->getPairCache()->setInternalGhostPairCallback(new btGhostPairCallback());
It is now this:
broadphase->getOverlappingPairCache()->setInternalGhostPairCallback(new btGhostPairCallback());
I am also using a .bullet file imported from blender, if that is relevant.
The issue was with the bullet file, which has since been fixed(the collision boxes weren't working). However, I still experience jitteryness, unable to step up occasionally, instant step down from to high a height, and other issues.
My answer to this question here tells you what worked well for me and apparently also for the person who asked.
Avoid ground collision with Bullet
The character controller implementations in bullet are very "basic" unfortunately.
To get good character controller, you'll need to invest this much.
All right, i apologize right away because the code is actually kind of big. The thing is, i am working with SDL, learning actually. I had managed to create animations, but i decided i wanted to go a little deeper. This is how the Code works
App - Uses: This has the main loop, the Init function, the Render Function and the whole softwares is originated from here.
Animation - Uses: This will contain and declare all of the functions in the Class Animation. It only works when a bool variable called Running is true.
Surface - Uses: This will Load files onto surfaces, Make certain color transparents and Draw images or part of images onto the MainSurface.
Events - Uses: This has all of the Virtual Functions to Events
Object - Uses: This is the big part. It was working perfectly. Before i would have a Surface Called Yoshi on the Main Class, and i would interact with the animation using that Surface. I thought that the method of having the "Character" on the main Class was a little bit confusing and it would cause me problems when having Multiple images on the screen. So therefore i decided to create a class called Object, which would have its own SDL_Surface, its own location on screen, Its own variable decided which frame it is. What i did was that i created an object to This class on the APP Class... Something like
Object MainCharacter;
So then i would be able to manipulate that Character alone, and if i ever needed to have another Object on screen i would just use
Object *SecondCharacter;
etc... So then the OBJECT Class would call the Animation. APP Class would render all of the images, by a function somewhat like this
MySurface::OnDraw(Surf_Display, MainCharacter.Img_Surface, MainCharacter.RetrievePosX(), MainCharacter.RetrievePosY(), MainCharacter.RetrieveFrameByID(0), MainCharacter.RetrieveFrameByID(1), 64, 64);
Well... But the thing is: The code stops working. This is far from a finished code, but i would like to fix this issue right away, so i can finish only after it already has a base.
Here are all of the files: Some of them dont have too many lines. I also wrote some comments to help anyone who may be able to help me.
HEADERS:
Animation.h - http://pastebin.com/v4REcmBd
Object.h - http://pastebin.com/KdeamZTG
Events.h - http://pastebin.com/dpQ7zwpG
CApp.h - http://pastebin.com/5zZYwDjv
Surface.h - http://pastebin.com/S66ChQ3f
SOURCES:
Surface.cpp - http://pastebin.com/KRgAkHpw
Object.cpp - http://pastebin.com/RtDRwVj4
Events.cpp - http://pastebin.com/dpXn8Rh3
OnRender.cpp - http://pastebin.com/AqgMTacb
OnLoop.cpp - http://pastebin.com/UAeAt7y6
OnInit.cpp - http://pastebin.com/1iiZVeyK
OnEvent.cpp - http://pastebin.com/AjRXnKC1
OnCleanUp.cpp - http://pastebin.com/cv0M11nV
CApp.cpp - http://pastebin.com/L0jhfWY8
Animation.cpp - http://pastebin.com/0BZhh6TG
All right those are it. Some of them are really short. Well, if anyone can help me finding where is my mistake i would be glad. And with that aside, i would really like to get an opinion on the structure of the software, do you think what i am doing is practical? What Design do YOU use when creating SDL Software or Games???
Having been told in the comments it happens on line 12 of Source.cpp which says
Res = SDL_DisplayFormat(Temp);
and googled SDL_DisplayFormat for you, I find this manual page
Near the bottom it says:
Newbie hint
You have to call SDL_Init before using the SDL_DisplayFormat function.
If you don't, your program will crash with an access violation.
for (int i = 0; i < Number_Of_queries; i++)
{
glBeginQueryARB(GL_SAMPLES_PASSED_ARB, queries[i]);
Box[i]
glEndQueryARB(GL_SAMPLES_PASSED_ARB);
}
I'm curious about the method suggested in GPU GEMS 1 for occlusion culling where a certain number of querys are performed. Using the method described you can't test individual boxes against each other so are you supposed to do the following?
Test Box A -> Render Box A
Test Box B -> Render Box B
Test Box C -> Render Box C
and so on...
I'm not sure if I understand you correctly, but isn't this one of the drawbacks of the naive implementation of first rendering all boxes (and not writing to depth buffer) and then using the query results to check every object? But your suggestion to use the query result of a single box immediately is an even more naive approach as this stalls the pipeline. If you read this chapter (assuming you refer to chapter 29) further, they present a simple technique to overcome the disadvantages of both naive approaches (that is, just render everything normally and use the query results of the previous frame).
I think (it would have been good to link the GPU gems article...) you are confused about somewhat asynchronous queries as described in extensions like this:
http://developer.download.nvidia.com/opengl/specs/GL_NV_conditional_render.txt
If I recall correctly there were other extensions to check for the availability of a result without blocking also.
As Christian Rau points out doing just "query, wait for result, do stuff based on result" might stall and might not be any gain because of that, depending on how much work is in "do stuff". In fact, doing the query, waiting for it to round trip just to save a single draw call is most likely not going to help at all.