I am trying to make a ball trail.
rBallPos is correctly updating.
Following code is not working creating
a cylinder as ball's trail. How to
solve it?
LPD3DXMESH /*ID3DXMesh*/ ppMeshCylinder = NULL;
hr = D3DXCreateCylinder(g_d3d_device,0.1f,0.1f,0.1f,1,1,&ppMeshCylinder,0);
hr is FAILED here also hr != D3D_OK
D3DXMATRIX cylinder, cylinder2, cylinderRotate, cylinderTrans;
D3DXMatrixRotationX(&cylinderRotate, 1.5f);
D3DXMatrixTranslation(&cylinderTrans, rBallPos.fX, rBallPos.fY, rBallPos.fZ);
D3DXMatrixMultiply(&cylinder, &cylinderRotate, &cylinderTrans);
g_d3d_device->SetTransform(D3DTS_WORLD, &cylinder);
ppMeshCylinder->DrawSubset(0);
Need help.
You need to pass in a pointer to LPD3DXMESH, so your mesh parameter should be &ppMeshCylinder instead of ppMeshCylinder. In fact, your compiler should have already warned you.
Update: Try passing in a larger value for Slices and Stacks, say 5 or 10. It's not possible to create a cylindrical mesh with just 1 polygon.
Related
I am trying to change the geometry of an existing TopoDS_Shape in OpenCASCADE. A possible application is for modifying an edge of a body without the need to reconstruct the whole body (e.g. change the radius of one cap of a cylinder, shift a control point in a Bspline curve/surface).
Is there a standard approach to do this in OpenCASCADE?
Is it possible to update geometry without creating a new shape?
I already tried to use BRepAdaptor_HCurve instead, but this did not really help.
Handle(Geom_Circle) aCircle = new Geom_Circle(gp_Ax2(gp_Pnt(0, 0, 0), gp_Dir(0, 0, 1)), 5); // create a circle in the xy plane, origin (0,0,0) radius 5;
TopoDS_Edge circ = BRepBuilderAPI_MakeEdge(aCircle); // switch to topological description;
STEPControl_Writer writer;
writer.Transfer(circ,STEPControl_AsIs); // access topology for output
BRepAdaptor_Curve theAdaptor = BRepAdaptor_Curve(circ); // create an adaptor
gp_Circ mod_circ = theAdaptor.Circle();
mod_circ.SetRadius(1); // change radius to 1
// I dont want to create a new circle, but reuse the old one with the updated geometry:
// writer.Transfer(circ, STEPControl_AsIs); // access topology for output
// in order to output the updated geometry, we also have to create a new edge
TopoDS_Edge another_circ = BRepBuilderAPI_MakeEdge(mod_circ);
writer.Transfer(another_circ, STEPControl_AsIs); // access topology for output
writer.Write("debug.stp");
Original and modified geometry, created by writing circ and another_circ
As i understood from the OpenCASCADE forum and the documentation you can not to change the subshapes of a shape directly. But you can create a new subshape and replace the old.
See OpenCASCADE forum topics below. Hope it helps.
How to modify sub-shapes of a given shape without copy
Modify shape
Replacing a face with X faces
Edit topology
I'm learning how to render objects with libGdx. I have one square model, that creates a few model instance from them. If I have only one model it renders fine.
But if I have more instances it doesn't properly. Looks like the front objects are draw first, and the background the last one, so always the background objects are visible and the front objects you can see through them.
To render I use the following
Gdx.gl.glViewport(0,0,Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
Gdx.gl20.glClearColor(1f, 1f, 1f, 1f);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT | GL20.GL_DEPTH_BUFFER_BIT);
mb.begin(cam);
worldManager.render(mb, environment);
mb.end();
mb variable is the ModelBatch instance, and inside worldManager.render each model instance is draw as follow:
mb.render(model, environment);
I'm not sure what is happening. But I think it is some GL attribute that I need enable
Is not 100% related to the following post because, yes it uses OPENGL like libgdx, but the solution provided in that post is not working and I think the problem comes from ModelBatch from libgdx
Reproduction of the problem
You didn't setup your camera correctly. First of all your camera's near plane is 0f, which means it is infinitely small. Set it to a value of at least 1f. Secondly you set the camera to look at it's own position, which is impossible (you can't look inside your own eyes, can you ;)).
So it would look something like:
camera = new PerspectiveCamera(90, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
camera.position.set(0, 10, 0);
camera.lookAt(0,0,0);
camera.near = 1f;
camera.far = 100f;
camera.update();
You probably want to start here: https://xoppa.github.io/blog/basic-3d-using-libgdx/
For more information on how the camera works have a look at: http://www.badlogicgames.com/wordpress/?p=1550
Btw, calling Gdx.gl20.glEnable(GL20.GL_DEPTH_TEST); will not help at that location and should definitely not be done when mixed with ModelBatch. ModelBatch manages its own render context, see the documentation for more information: https://github.com/libgdx/libgdx/wiki/ModelBatch
There are a lot of possible answer, but I would say that
glEnable (GL_DEPTH_TEST) ;
could help if you haven't done it yet. Also, enabling depth buffer only works if you actually have a depth buffer, which means you must makes sure you have one, and the method for this depends on your window context.
for show the difference dimentions you can use the fog
I'm trying to build a sprite from an image. Using Image and Texture2D class and then later creating a sprite from the texture2D.
The image I am loading is 512x512 and I expected both versions of the createWithTexture to behave the same but they don't. Here the code:
Image* image = new Image();
image->initWithImageFile(fileName);
Texture2D* texture = new Texture2D();
texture->initWithImage(image);
//If used this way everything works as expected
Sprite* spr= Sprite::createWithTexture(texture);
//If used with a Rect weird result occurrs.
Sprite* spr= Sprite::createWithTexture(texture,Rect(0,0,512,512));
spr->setAnchorPoint(Vec2(0,0));
spr->setPosition(Vec2(0,0));
spr->setScale(1.0f,1.0f);
this->addChild(spr);
Here the result of the first one using a Rect:
And here the Second version without a Rect:
Do anybody know what is happening? I need to use the method that uses the rect because I will be creating a bunch of sprites from this image in the future.
Edit1: After debugging both versions of the sprite. I have noticed that the one created without the Rect shows a rect of 0,0,240,240. Instead of 0,0,512,512 as I provided. Why 240?
Thanks in advance.
I managed to figure out what was happening. Cocos2D-x uses director->setContentScaleFactor and glview->setDesignResolutionSize as a way to make things easier for multi resolution/device games. When you build the Rect to get a part (or full) texture you must have into account the CC_CONTENT_SCALE_FACTOR() macro, in order to get correct target coordinates.
This can be checked at this link: http://www.cocos2d-x.org/wiki/Multi_resolution_support
Cheers.
If your vecSize is bigger than the image's size, the image will be out of shape.
So if you don't know the image's real size, don't set it.
Sorry I'm a bit new with SDL and C++ development. Right now I've created a tile mapper that reads from my map.txt file. So far it works, but I want to add editing the map now.
SDL_Texture *texture;
texture= IMG_LoadTexture(G_Renderer,"assets/tile_1.png");
SDL_RenderCopy(G_Renderer, texture, NULL, &destination);
SDL_RenderPresent(G_Renderer);
The above is the basic way I'm showing my tiles, but if I want to go in and change the texture in real time it's kind of buggy and doesn't work well. Is there a method that is best for editing a texture? Thanks for the help I appreciate everything.
The most basic way is to set up a storage container with some textures which you will use repeatedly; for example a vector or dictionary/map. Using the map approach for example you could do something like:
// remember to #include <map>
map<string, SDL_Texture> myTextures;
// assign using array-like notation:
myTextures["texture1"] = IMG_LoadTexture(G_Renderer,"assets/tile_1.png");
myTextures["texture2"] = IMG_LoadTexture(G_Renderer,"assets/tile_2.png");
myTextures["texture3"] = IMG_LoadTexture(G_Renderer,"assets/tile_3.png");
myTextures["texture4"] = IMG_LoadTexture(G_Renderer,"assets/tile_4.png");
then to utilise a different texture, all you have to do is use something along the lines of:
SDL_RenderCopy(G_Renderer, myTextures["texture1"], NULL, &destination);
SDL_RenderPresent(G_Renderer);
which can be further controlled by changing the first line to
SDL_RenderCopy(G_Renderer, myTextures[textureName], NULL, &destination);
where textureName is a string variable which you can alter in code in realtime.
This approach means you can load all the textures you will need before-hand and simply utilise them as needed later, meaning there's no loading from file system whilst rendering:)
There is a nice explanation of map here.
Hopefully this gives you a nudge in the right direction. Let me know if you need more info:)
I'm trying to set up something in SDL [in C++] where I can draw a one pixel big rectangle. I've got everything in my code working except my second SDL_Surface called rectangle. I'm having trouble initializing it. Here's the line where I try to initialize it:
rectangle = SDL_Surface(SDL_DOUBLEBUF | SDL_HWACCEL |
SDL_SRCALPHA | SDL_HWSURFACE,
screen->format, 1, 1, 16, NULL, clip_rect, 1);
Thank you for taking the time to read this and any answers you might choose to give.
I think that the main problem you are having is that there is no SDL_Surface function. To create a new surface, use SDL_CreateRGBSurface. Be sure to call SDL_FreeSurface on the returned surface after you are done with it or you will leak memory.
Additionally, I am not sure why you are creating a surface for the rectangle. A cleaner way of drawing a solid-color rectangle is SDL_FillRect without creating a new surface.