Othographic Projection in XTK - xtk

So I am using XTK to develop a app that will allow users to view multiple 3D meshes in one renderer. The problem is that it uses a perspective camera instead of a orthographic, which causes panning to 'rotate' the meshes a bit. Has anyone been successful in getting XTK to render orthographically without modifying source code? I would rather not modify it but if I have to I will. Thank you!

So from what I can see, there's no way to set a 3D camera to be in orthographic perspective without modifying the source code. However, it seems fairly straight forward to add that functionality. If you add the following in a function to camera3D.js, that should get the right result (I tested it on XTK Tutorial 00).
this._perspective = X.matrix.makeOrtho(X.matrix.identity(), -100, 100, -100, 100, 1, 10000);
It uses goog.vec.Mat4.makeOrtho

Related

3d picking from arbitrary viewpoint

I created a 3d scene of many pipes (valves,manhole) of different colors and materials . Now I want to use the mouse to pick them and get their attributes(color,material). I've tried to use glupushmatrix, the method provided by OpenGL API ,it worked when the viewpoint is almost right in front of the pipe.But when looking from different viewpoints ,such as from (0,1,1) to (0,0,0),it can't do it. What's more , I didn't find any projection settings for functions glulookat before glupushmatrix . I also tried to use ray tracing based picking using math , but I found it is difficult to do intersection testing for each pipe using brute force .
OpenGL provide a special render mode (GL_SELECT) to help achieving picking.
To implement it you have to:
Name your selectable primitives
Add a rendering pass with GL_SELECT mode.
edited the link:
Follow this tutorial...

How to do .png image blur using DirectX9 without using advance 3d features HLSL / Per Pixel motion blut / Vertex Shader

Can anyone please help me how to do .png image blur using DirectX9 (2d graphics feature of d3d) without using the advance 3d features like High Level Shader Language(HLSL), Direct3D Per Pixel Motion blur and Vertex Shader.
Detailed explanation:
I've a row of 6 adjacent .png images(6 Sprite textures) on a surface and then I continuously moving/changing the texture locations in a circular fashion (1->2->3->4->5->6->1->2->3->4->5->6) with varying alpha component for getting the feel of spinning effect (2 dimensional spinning).
Problem:
Even with varying sprite texture alpha values and varying frame per sec(fps) I didn't get the real feel of spinning apart from continuous image change. After so many web search I found the clue that it is possible to get the spinning effect if I apply the blur effect(Gaussian blur / box blur) in .png file on the fly.
But due to 3d support restriction in my target platform I can't use the advance 3d features of direct3d apart from 2d features for getting the spinning effect (kind of motion blur).
I warmly welcome the forum member for their kind help / suggestion / Sample code / directing me to right path for solving this problem.
Sample Code:
void D3DGraphics::DrawSprite(LPDIRECT3DTEXTURE9 &texture,ID3DXSprite* pSprite, DXVECTOR2 Trans_11, int ImgIndex) {
D3DXMATRIX Matrix;
pDevice->Clear( 0,NULL,D3DCLEAR_STENCIL,D3DCOLOR_XRGB(0,0,0),0.0f,0 );
pSprite->Begin(D3DXSPRITE_ALPHABLEND);
D3DXMatrixTransformation2D(&Matrix, NULL, NULL, NULL, NULL, 0, &Trans_11);
pSprite->SetTransform(&Matrix1);
--> Need blur effect before write operation / while loading .png file as texture <---
pSprite->Draw(texture[ImgIndex], NULL, NULL, NULL, 0xFFFFFFFF);
pSprite->End();
}
If cycling through 6 images isn't enough to provide smooth animation, why not cycle through say 12 or 24? If you only have 6 "original artworks" it'd still be easier to generate the intermediate images up front using photoshop/imagemagick type tools and just having your app load load them than trying to do it in DirextX.
Here is A Link to C++ Box Blur to one chinese's website blog
hope

Rotating a 3D mesh in direct x

I have inhereted a Direct x project which I am trying to improve. The problem I am having is that I have 2 meshes and I want to move one independent of the other. at the moment I can manipulate the world matrix simply enough, but I am unable to rotate an indervidual mesh.
V( g_MeshLeftWing.Create( pd3dDevice, L"Media\\Wing\\Wing.sdkmesh", true));
loades the mesh and later it is rendered
renderMesh(pd3dDevice, &g_MeshLeftWing );
Is there a way I can rotate the mesh. I tried transforming it using a matirx with no success?
g_MeshLeftWing.TransformMesh(&matLeftWingWorld,0);
any help would be great
Firstly, you appear to be loading a ".sdkmesh" file. It was documented heavily in the DirectX SDK that ".sdkmesh" was made for the SDK and should not be used as an actual mesh loading/drawing solution.
Therefore I would advise you start looking at alternative means to load and draw your model, not only will that give you a greater understanding of DirectX, but it should ultimately answer your question in the long run!

Tracking camera movement and object orientation in xtk

This is a followup to Matt's previous question about camera orientation. I'm working with him on a javascript interface for a python analysis code for 3D hydro simulations.
We've successfully used xtk to build a 3D model of the mesh structure in our simulation. The resulting demo looks a lot like the simple cube demo on the xtk website so your advice based on that demo should be readily portable to our use case.
We were able to infer the view matrix at runtime from the XTK camera object. After a lot of poking and some trial and error, we figured out that the view matrix is really (in openGL nomenclature) the model-view matrix - it combines the camera's view and translation with the orientation and translation of the model the camera is looking at.
We are trying to infer the orientation of the camera relative to the (from our point of view) fixed model as we click, drag, and zoom with respect to the model. In the end, we'd like to save a set of keyframes from which we can generate a camera path that will eventually be exported to python to make a 3D volume rendering movie of the simulation data. We've tried a bunch of things but have been unable to invert the model-view matrix to infer the camera's orientation with respect to the model.
Do you have any insight into how this might be done? Is our inference about the view matrix correct or is it actually tracking something different from what I described above?
From our point of view it would be really great if xtk kept track of the camera's up, look, and position vectors with respect to the model so that we could just query for and use the values directly.
Thanks very much for your help with this and for making your visualization toolkit freely available.
This page might be useful as long as I'm understanding your needs http://3dgep.com/?p=1700 . It gives a very well understanding of the View Matrix which i needed myself and about half-way down the page might be a bit of info you could use http://3dgep.com/?p=1700#Converting_between_Camera_Transformation_and_View_Matrix .

Best way to rotate an image using SDL?

I am building a game and the main character's arm will be following the mouse cursor, so it will be rotating quite frequently. What would be the best way to rotate it?
With SDL you have a few choices.
Rotate all your sprites in advance (pre-render all possible rotations) and render them like you would any other sprite. This approach is fast but uses more memory and more sprites. As #Nick Wiggle pointed out, RotSprite is a great tool for generating sprite transformations.
Use something like SDL_gfx to do real-time rotation/zooming. (Not recommended, very slow)
Use SDL in OpenGL mode and render your sprites to primitives, applying a rotation to the primitives.
Option 3 is probably your best bet because you gain all of the advantages of using OpenGL. It's really up to you how to want to do it. It's also a possibility that you can load your sprites, perform all rotation calculations with SDL_gfx and then save the rotated versions to an SDL_Surface in memory.
EDIT: In response to your comment I would recommend checking out Lazyfoo's SDL tutorials. Specifically, this one about rotation. There is also an OpenGl function, glRotatef, which can be useful in your case. A quick search brought back this little tidbit which could also be helpful.
SDL_RenderCopyEx()
has extra arguments for rotation, flipping, and the rotation center.
You can use a library like SDL_gfx