How to implement translation & rotation widgets for game level editor - directx

I am developing game editor.To detect mouse hit on 3D model I am using mouse picking concept.
But I want to implement translation & rotation widgets like other game editor with actual arrows at the center of model in three direction.
How to achieve this..?
Can anyone suggest sample code for the same?

Any given object you select will have a local-to-world transform matrix.
Using DirectX its pretty easy to get the 3 Axes.
The first row of the matrix if the side (x) vector.
The second row is the up (y) vector.
The thidd row is the forward (z) vector.
Knowing the position (the 4th row) makes the trigonometry pretty easy to work out. Thus its pretty simple to do rotations and translations based on this info.

Related

How to make a bowling pin like structure in webgl

I want a structure like this:
I have made a cylinder and placed a smaller cylinder on top of it.
For the base cylinder I was thinking of smoothly increasing the x-coordinate till the half of max(y co-ordinate) as y increases and then smoothly decreasing x for y > half(max(y co-ordinate)) as y increases.
But rotating the shape distorts it.
Is there a way to make a shape like this using basic webgl and not any advanced libraries such as Three.js.
As I mentioned in the comments the most common way to make shapes for 3D is to use a 3d modeling package like Blender or Maya or 3D Studio Max or DAZ or Cinema4D etc...
If you really want to do it in code though, well the most obvious idea is to make a function that makes a cylinder then pinch it in the right places using a sine wave. That probably won't get you want you want though because you'll need to make the cylinder very high res (lots of vertices) in order for the top round part to become smooth.
The way a 3D modeling package would likely do this is you'd use a spline to create the 2D outline of the bowling pin. You'd then "lathe" or rotate the spline around the center to generate vertices. The modeling package would have settings for how many points to place along the spline and how many points around to generate. It would also have settings to decide whether to place points at equal distances along the spline or to do some kind of curve fitting / error accumulation to figure out where more points are needed and where less points are needed.
I ended up being curious about this so I wrote an article about it

de Casteljau algorithm Objective-C

I'm not very mathematically inclined, so it would be great if someone could provide me a code example of de Casteljau algorithm in Objective-C. I'm attempting to calculate the points along a curve between a start point and an end point. Basically what I'm trying to do is create view that looks similar to a UIActivityIndicatorView. I would just use images, but it needs to be dynamic and have any number of ticks. My plan was to draw the view in four quadrants, top-left, top-right, bottom-right, bottom-left. I was basically just going to draw one quadrant and then just create that view 3 more times and apply transforms to them to complete the circle.
I would appreciate any help, thanks!

Z-order implementation in XNA: cyclic overlapping?

What would be the best approach for implementing a z-order system, where something like the following becomes possible:
There are 4 rectangles: A, B, C and D.
Rectangle A overlaps Rectangle B.
Rectangle B overlaps Rectangle C.
Rectangle C overlaps Rectangle D.
Rectangle D overlaps Rectangle A.
Just like a cardboard box. I believe it's called cyclic overlapping.
I know this is a wierd question, but I was just wondering... :)
The thing about the cardboard box example is that the pieces of cardboard are not exactly aligned towards the camera. In essence it is a (rather flat) 3D structure of slightly tilted planes that overlap eachother. As far as cardboard boxes go they're also not planar but slightly bent in order to close the box. In MS-paint pseudo perspective:
This is possible in 3D by tilting the planes so that they overlap. This is a case where the painters algorithm fails, and is one of the reasons where the Z buffer comes in handy to resolve which of the object actually occludes the other.
If you are working in a purely 2D world and you cannot tilt the planes to achieve the pseudo-3D effect that you're after you would need to subdivide the planes and draw the overlapping parts using a different Z level than you would use for the rest of the box - essentially doing your own clipping.
You might be able to get by by doing some sort of Z-buffer trickery to emulate the same thing as well, but essentially you should use a 3D structure for what is a 3D problem.

Simple Delphi 3d functions

Could anyone help me with examples of some bare-bone, old school 3d methods in Delphi? Not using openGL or firemonkey or any external library (vanilla canvas coding). What i want to do is to be able to rotate X number of points around a common origo. From what i remember from the old days, you subtract left from right (on the 3d points) so that origo is always 0,0 - then perform the calculations, and finally add the left/top pixel offset to get the actual screen positions.
What im looking for is a set of small, ad-hoc routines, ala:
RotateX(aValue:T3dpoint; degr:float):T3dPoint;
RotateY(--/--)
RotateZ(--/--)
Using these functions it should be fairly easy to create the old "rotating 3d cube" (8 points).
Also, are there functions for figuring out the visible "faces"? If i want a filled vector cube, then i guess i need to extract visible regions (based on distance/overlapping?) which in turn is drawn as X number of filled polygons? And these must no doubt be sorted by depth to not come out a mess.
for instance:
PointsToFaces(const a3dObject:T3dPointArray):TPolyFaceArray;
SortFaces(Const aFaces:TPolyFaceArray):TPolyFaceArray;
Any help is welcome!
Here are some nice good-old resource for Delphi Math from efg's Reference.
You can find a list of graphic projects.
2D/3D Lab Vector graphics: translation, rotation, scaling, view transform, homogeneous coordinates, clipping, projections, vectors, matrices etc...
I did write a simple 3D rendering 'engine' a few years ago, using only naïve linear algebra. Might not be the most efficient one, though. A few thousand of points is the limit if you want to be able to move reasonably smooth. Sample EXE. You can get the code if you like, but it might not be that pretty.

Basic pathfinding with obstacle avoidance in a continuous 2D space

I'm writing a simulation in which a creature object should be able to move towards some other arbitrary object in the environment, sliding around obstacles rather than doing any intelligent pathfinding. I'm not trying to have it plan a path -- just to move in one general direction, and bounce around obstacles.
It's a 2D environment (overhead view), and every object has a bounding rectangle for collision detection. There is no grid, and I am not looking for A* solution.
I haven't been able to find any tutorials on this kind of "dumb" collision-based pathfinding, so I might not be describing this using the most common terms.
Any recommendations on how to implement this (or links to tutorials)?
Expanding on what Guillaume said about obstacle avoidance, a technique that would work well for you is anti-gravity movement. You treat local obstacles as point sources of antigravity, the destination as gravity, and your computer controlled character will slip (like soap!) around the obstacles to get to the destination.
you can combine two steering algorithm :
seek : you apply a steering force in the direction which is the difference between the current velocity and the desired velocity towards the target
Obstacle Avoidance : you anticipates the vehicle's future using a box whose length is a constant time multiplied by the current velocity of the vehicle. Any obstacle that intersects this box is a potential collision threat. The nearest such threat is chosen for avoidance. To avoid an obstacle, a lateral steering force is applied opposite to the obstacle's center. In addition, a braking (deceleration) force is applied. These forces vary with urgency (the distance from the tip of the box to the point of potential collision). Steering varies linearly, braking varies quadratically.
You can find more on the website "Steering Behaviors For Autonomous Characters"
regards
Guillaume
PS : this assume you're using a point/velocity/acceleration method for the object's movement.
Maybe you could use Pledge's algorithm
Whenever your creature, travelling in vector direction v, collides with a wall whose direction is represented by vector w, the direction that you need to "slide" is given by the vector that is the projection of v onto w. This can be found using
v . w
--------- w
|w|*|w|
where . is the vector dot product and |w| is the magnitude of vector w ( = sqrt(w . w)). If w is a unit vector, this becomes simply
(v . w) w
Using the resulting vector as your creature's speed will mean your creature travels quickly when it just "grazes" the wall, and slowly when it hits the wall nearly dead-on. (This is how most first-person shooter games manage collisions for the human player.)
If instead you want your creature to always travel at full speed, you only need the sign of v . w -- you will always be travelling either in the direction the wall faces (w) or the opposite direction (-w).
The issue that you will have is when your creature hits the wall dead-on. In that case your projected vector will be (0, 0), and you need some other technique to decide which way (w or -w) to go. The usual approach here is A*, although this may be unnecessary if your environment possesses enough structure.
I posted a pathfinding algorithm in C# a while back
Here's the link
You can try and use it as a starting point, ie, you could modify the function that checks the next cell to see if it's valid to check for the obstacles, and you could feed it small intervals instead of the starting and end points, kinda like multiple mini-pahfinding routes.
(The text is in spanish, but you can download the application from the link at the top)

Resources