So first some background. Im developing a really simple 2D game, in Delphi 10.3, FMX, which at the bottom of the screen draws a random terrain for each level of the game.
Anyway, the terrain is just some random numbers which are used in Tpathdata and then i use fillpath to draw this 2d "terrain".
I want to check when a "falling" object, a trect for example, intersects with this terrain.
My idea was to get all the points of the tpathdata, every Y position of every X position of the screen width. This way i could easily check when an object intersects with the terrain.
I just cannout figure the way how to do it, or if anyone has any other solution. Id really appreciate any help. Thanks
This is not really a Delphi problem but a math problem.
You should have a math representation of your terrain. The polygon representing the boundary of the terrain. Then you need to use the math to know if a point is inside the polygon. See Wikipedia.
You may also implement it purely graphically using a B/W bitmap of the same resolution of the screen. You set the entire bitmap as white and draw the terrain on the bottom in white. Then checking the color of a pixel in that bitmap you'll know if it is outside of the terrain (black) or inside the terrain (white).
Related
This is an example of a drawing for the program I use
DrawCircle(mousePos.x, mousePos.y, mousePos.z, 650, ARGB(255, 255, 0, 0))
pretty simple x,y,z location radius of the circle and color, in this example it will draw a circle around my mouse and if my mouse moves the circle moves with it as is should, however what I would like to do is know how to draw a circle at lets say stationary position x,y,z and make the circle move from said position to new position a,b,c at x speed. sure I can just disable the draw at the starting point and redraw it at the destination point but I want the circle to visually move from point a to point b at speed x and I'm not sure what math I would need to be able to do this, furthermore if I was to draw a line how could I rotate that line in place so it looked like lets say helicopter blades spinning? Any help is appreciated thank you.
Not sure about LUA per se, but the solution to your problem is based around vector mathematics. LUA may have provide transformation functions to move a point in 3D space... not sure. As for the rotor blade question, if you are plotting the rotor blade in a 2D plane, you simply need a bit of trigonometry. There are lots of examples on the web, e.g.: trig example
I am really having a problem with this.
I have a polygon (a quad) which can be any shape. When my mouse is inside the polygon I need to find the x,y values of where my mouse is (inside the quad) as though the poygon were are perfect square. Further explanation; I have a 32x32 texture applied to the polygon and I need to know the x,y of the texture that the mouse is over.
I have some code that works for most shapes but which breaks if TR.Y is less than TL.y for instance.
I have some pretty simple code that tests whether the cursor is inside the polygon (via two triangle tests). But I cannot figure out how to use this to generate an x,y of a virtual square projection.
This problem is killing me. What is the name of operation i am trying to perform? Does anyone know of an explanation where the equations are presented in code form (any kind of code) (rather than just mathematical notation?). Any kind of help would be so appreciated.
I am on the verge of doing a 2nd render with specially formatted textures (each pixel having a unique value) so that I can just colour test to get an approximate x,y match (and precision is something that can be compromised here without causing too much trouble) - but then I will have to work around the DX Lib's attempt to blend and smooth the special texture as it is warped to fill the quad)
**Edit: Code that works for many quad shapes
It depends on method - how the texture is drawn at this quad.
If it uses perspective transform Square=>Quad, you have to use matrix of inverse transform Quad=>Square. Short article
For linear interpolation approach see this page
i have a question about achieving an effect like on a lunar eclipse. The effect should look like in the first seconds of this gif. So just like a black shadow which goes over the circle. The ideal situation would be a function where i can passed a parameter in percentage to get this amount as a shadow on the circle:
The problem which i am facing is that my background is an gradient. So it's not possible to have a black circle which moves over the moon to get the effect.
I tried something with CCClippingNode but it looks not nice. Furthermore the clip on the edges was always a bit pixelated.
I thought about using something like a GLSL Shader to achieve the effect but i am not so familiar with GLSL and i can't find an example.
The effect is for an app game developed for an iphone. I use the cocos2d framework in version 3 (the current one).
Has somebody an idea how to get this effect? An idea where i can start to search?
Thank you in advance
The physics behind is simple you change the light shining on the moon. So
I would create a 1D gradient texture representing the lighting conditions
compute each rendered pixel of moon
you obviously have the 2D texture of moon. So you now need to obtain the position of each pixel inside the 1D lighting texture. So if moon is fully visible you are in sunlight. When partially eclipsed then you are in the umbra region. And finaly while total eclipse you are in penumbra region. so just compute the middle point's of the moon position. And for the rest use relative position in the moons motion direction.
So now just multiply the Moon surface with the lighting texture and render the output.
when working you can add the curvature correction
Now you got linerly cutted Moon phases but the real phases are curved as the lighting conditions differs also with radial distance from motion direction and moons center. To fix this you can do
convert the lighting to 2D texture
or shift the texture coordinate by some curvature dependent on the radial distance
I want to draw a line with dynamic width as shown in attached picture. What should be the best approach for this. ?
Updated:
My task is to draw line on finger move. And the line width is changes as speed of swipe is change. both (Line width and finger swipe speed) are directly proportional .
As the image you posted doesn't has any consistent height-width proportion to calculate and change, i doubt this cannot be achieved.
In other solution you can draw a line of fixed pixel say 2 pixel and based on drawn length inflate the width if line till center and then again start deflate from center point to end point.
You need to see the difference between x coordinates otherwise if a sine wave is drawn with high nodes the line width will overlap each other.
Edited : This link might be of your interest then.You can modify it according to your need, its in cocos2d.
There is no direct support for variable thickness curves in iOS (or Mac OS for that matter.) The cocos2d project looks like a good approach.
There is also no support for soft-edged curves who's edges are feathered to transparent. I've thought about implementing a similar approach to the one outlined in the Cocos link using OpenGL. This would be a good application for a vertex shader, since it would take advantage of the parallel vertex processing and vector math available in shaders.
Take a look at this article Smooth Freehand Drawing. It might be helpfull.
You can manipulate with control points of
[path addCurveToPoint:pts[3] controlPoint1:pts[1] controlPoint2:pts[2]];
and fill the area between two bezierPaths. I am not sure if it will work, but you can try if you dont find anything else.
Every CCSprite is a regtangle area, but some of the parts of it, is visible ,means image that we see and other part are not. So i want to know when i touch on CCsprite whether the touch point is visible area or transparent area, Any way to check this, like getting the pixel color of the touch point??
It's possible to do this with OpenGL API, but it would be wrong solution. I propose to detect tap point inside sprite shape (that would be manually defined). To calculate bounding shape you may use for example this tool: SpriteHelper. To check point inside polygon (even non-convex) there is good algorythm: Determining if a point lies on the interior of a polygon. I use this method in my iPhone game.
As for efficienty of this method compared to direct checking of pixel opacity:
performance: to get pixel in OpenGL you need to lock texture and read data from it, this will drop FPS
accuracy: tap is not a mouse click, it means some region, so you would probably check some area (for example circle of tap) inside sprite shape
flexibility: you may tune your shape as you want
PS: If you definitely want to check pixels, a good solution will be to make additional boolean map of texture pixels (where each bit responds to pixel treshold).