Tag Info

Hot answers tagged

12

Given a "root" curve, here's how you might generate block vertices. The root curve is in the middle, in black. Its control points are shown with red Xs. In short: I made a Bézier and sampled it (at a configurable rate). I then found the perpendicular vector of the vector from each sample to the next, normalised it, and scaled it to to a (configurable) ...


11

What would the W3C do? The internet has had this problem. The World Wide Web Consortium noticed. It has a recommended standard solution since 1999: Scalable Vector Graphics (SVG). It's an XML-based file format specifically designed for storing 2D shapes. "Scalable-what?" Scalable Vector Graphics! Scalable: It's meant to scale smoothly to any size. ...


10

Let A and B be two points on the black line. Let C and D be your blue segment. The sign of the z coordinate of cross product AB^AC tells you whether C is "left" or "right" of the black line. Similarly, cross product AB^CD tells you whether CD steers "left" or "right" of the black line. We don't really want to know whether it's left or right; all we want is ...


6

Just Google closed bezier curve, there are plenty of useful results, including one that has a code example It's just like a open bezier curve, but for the "next" point on your last point, you use the first point.


6

There are multiple types of Splines, Bezier curves are one of them. Beziers aren't required to pass through the points that define them. From the looks of it, you want a regular cubic spline. It will ensure that the line crosses through the points specified. You can find some interactive examples of different types here. Also, I know you're busy being an ...


6

There is rarely a "right way" or "wrong way" when it comes to game design. There are many, many ways to solve this problem, but here are a few possible approaches to explore: Constrain the tunnel pieces to both start and end only in certain directions; for instance only along the axes. Then you just have to keep track of the offset from the beginning to ...


5

I think you have two problems: Non-symmetric control points Initially you start with equal distances between p0 to p1 and p1 to p2. If the tolerance angle between the line segments is not met, you move p1 and p2 forward, but keep p0 where it was. This increases the distance between p0 to p1 while keeping the distance between p1 to p2 the same. When you ...


4

I would suggest something you haven't listed. Don't "create" your track at all. Rather, define it indirectly by placing a bunch of collide-able objects around where you want your track to be. Walls, old cars, wrecked buildings, semi-transparent-laser-beams... whatever you want. Heck, they don't even have to be visible. Then you can do your collision ...


4

My answer will cover the following topics: How to form a suitable Bezier curve for turning a character or a car smoothly. How to maintain the same speed across the curve. How to change the angle smoothly during motion. This is suitable for any character in any 2d game with a top down view and with minor adjustments could be used for 3d games as well. ...


4

Well, first of all you need a way to descrive such path. I would use some spline curves like Bezier curves or Hermite Splines to describe the path, and let the button follow that path once pressed. Unfortunately these curves are not available as is, you need to implement them. If you are interested here you can find 2 nice Herman Tulleken's ...


3

Your code contains a misleading comment: dstPath.quadTo(p2[0] , p2[1], p3[0], p3[1]); //create a curve to the third point through the second A quadratic bezier curve does not go through the second point. If you want to go through the second point you need a different type of curve, such as a hermite curve. You may be able to convert the hermite curves ...


3

To get a smoother intersection of two paths, you could scale them up before intersection and scale them down after. I don't know if it's a good solution, but it worked well for me. It's also fast. In my example, I intersect a rounded path with a pattern I created (stripes). It looks good even when scaled. Here my code: Path mypath=new ...


3

A quick google search shows this to be a common problem with line strips. I strongly suspect the correct answer is: don't use line strips. Use triangles instead, and build your own geometry so that it doesn't have gaps. Moreover, according to this answer on StackOverflow, it sounds like line rendering is not rigidly specified by the OpenGL spec the way ...


3

As the comments ask: How are you representing your curve (i.e. "drawn line")? Anyway, any representation should be possible to convert into a list of points that represent the curve to some precision. It might look something like this: Naive algorithm Go through adjacent point pairs and check if they intersect with another point pair that isn't the ...


3

Here is my try. The following algorithms are far from perfect, but they are simple and I believe you should start with this, check whether they work in your situation, and switch to something faster and/or more accurate later. The idea is the following: Sample the Bézier curve, find the nearest point on that sample Sample a neighbourhood around the found ...


3

You could create a Bézier curve that matches a sine (read this article for an example). Creating a Bézier curve from a sine, just to feed into CCBezierTo seems like a very counter-intuitive way of doing things though. I would skip CCBezierTo entirely and update the position of your sprite yourself. You could do so in your update method or implement a ...


2

First of all we need to know how a beizer curve is generated. according to it's wiki page, a Quadratic beizer curve is a function of t stated as follow: In this formula t is a variable between zero and one and all other parameters are vector values (it means B(t), P0, P1, and P2 have values for x and y in 2D world). the next thing you should know is how to ...


2

Assuming start point is the green circle, and end point is the red arrow Compute the distance between the start point as DS and the black segment, and do the same for the end point (red arrow) as DE. If DS>DE, then the segment is pointing toward. if DE>DS, it is pointing away. If both are equal, the two are parallels. You can find how to compute the ...


2

You might want to look into Phong tessellation and PN triangles. The idea with both of these techniques is to start with an ordinary triangle mesh with vertex normals - just as you would build in a standard art pipeline. Smoothed vertex normals fake the appearance of a curved surface, and the goal of both of these techniques is to actually generate a ...


2

Look at polygon interpolation (http://en.wikipedia.org/wiki/Polynomial_interpolation) Basically, you take n equispaced nodes (optimal interpolation is not equispaced, but for your case it should be good enough and easy to implement) You end up with a polygon of order n which decreases the error between your curve if (<-- big if) your line is smooth ...


2

This isn't a problem with line strips. OpenGL is doing exactly what you have asked it to do: draw a bunch of rectangles oriented to match the 'lines' you've provided, each with a particular width which you've also provided. The problem is that you're imagining that OpenGL is going to magically join up the corners of those rectangles into a single swooping ...


2

You could model your cave as a sequence of points, each with an associated size, with lines connecting them. Then treat each point and line as metaballs and metacylinders. This gives you a basic shape for your cave, to which you might want to start adding variation, such as by randomly offsetting vertices.


2

Here's another approach to procedural generation that hasn't been explicitly mentioned yet: spline skinning. You can use a version of Hermite Splines (which provide a curve interpolating positions and tangents) to define the curves: when it's time to generate a new segment, just choose a position (roughly in the direction of the previous segment, as bcrist ...


2

Here's a technique I experimented with recently. My RenderMonkey prototype shows a section of badlands-style canyon, but the same principle should work in caves. The idea is to start with tiles that are generic, downright boring, with simple predictable edges so they're easy to line up without seams or gaps: These starting tiles could be shapes you've ...


1

I think the sin function is still slow. You can approximate it with a function like y = 1 - (x - 1) ^ 2 The code looks like this: /** * @src_x source x coordination * @dst_x destination x coordination * @time_len length of time * @time_cur current time (from 0 to time_len) * @final_x output result of x coordination * * math ...


1

Simple harmonic motion is still easy to achieve with a sine wave and sin is a pretty fast function. However, there are some optimizations you can make since you'll be using it over and over. Since this movement code does not require much accuracy from sin, you can limit the input to sin and store the results. Using something like a hash table or in this ...


1

You do not HAVE to use the right side of the left side. You actually choose around which axis you want your EP curve to revolve: If you have a curve like this one: You can revolve around X-axis: You can revolve around Y-axis: You can revolve around Z-axis Or you can revolve around a freely defined axis (1,1,-1 here):


1

Just for what concern GUI you can use UIToolkit. It's free and opensource and already have the methods that you need for doing simple gui movement (you can call the delegate with the Action onTouchUpInside). There are also a demo scene that reproduce what you want to do, and with this library you can make all your GUI's element with a single draw call ...


1

Is there a reason for going for curves as opposed to straight lines? Straight lines are simpler to work with, and can be rendered efficiently in hardware. The other approach worth considering is to store a couple of bits per pixel, stating if it's inside, outside or on the outline of the shape. This should compress well, and might be more efficient than ...


1

If the point of the conversion is for storage only, and when you render it back on the screen you need it to be smooth, then the highest fidelity storage you can get, while still minimizing the total storage required to persist a given curve might be to actually store the attributes of the circle (or an arc, rather) and re-draw it on demand. Origin. Radius. ...



Only top voted, non community-wiki answers of a minimum length are eligible