I am using the CatmullRomSpline class of libgdx for creating a smooth curve passing through three points. Basically I want to place coins between two platforms in a curved path. For that I followed the following algorithm
Take the end top point of first platform as the first control point;
Take the middle point bw top end of first platform and top start of second platform , add a little height to it in y direction and take this point as second control point.
Take the top start point as second platform as third control point.
Now when I am trying to create a smooth path for my coin generation using these three control points, I just get one value what so ever t is use (CatmullRomSpline uses a float value t as parameter which has to vary bw 0 and 1).
Is there something I am missing . Is it that I need to provide more control points ?
Related
I am doing some math projects that require a lot of vector line art--that is a line drawn between to points with a circle at the start point and an arrow at the end point. A call to Math.atan2() keeps the arrow aligned. I call this class DrawVectorLineArt() and it creates instances of 2 other custom classes DrawArrow() and DrawCircle().
So far so good--DrawVectorLineArt() draws just what I need. Now I need to animate the vector art.
So in a function onEnterFrame I want to update the postion of arrow and circle, the objects created by DrawArrow() and DrawCircle(), respectively. I also need to clear and redraw the line drawn between them. At this point I am not sure how to proceed in an OOP framework. Do I need to create methods of my custorm class DrawVectorLineArt() to update the position of arrow and circle and subsequently clear and redraw the connecting line?
Any advice or links appreciated. Thanks!
"Do I need to create methods of my custorm class DrawVectorLineArt() to update the position of arrow and circle and subsequently clear and redraw the connecting line?"
Yes.
The arrow and the circle are very members of DrawVectorLineArt, and going by its name and choice of members, so should the line (if it's implemented through actual data). DrawVectorLineArt should contain and implement the whole animation between the circle, arrow, and line. As such, if the animation's supposed to be able to change after creation, the same instance of DrawVectorLineArt should be able to take any two legitimate points supplied to it (or that it becomes aware of internally, depending on what you're doing), reposition the three components, and turn the arrow and line appropriately, within its own code.
I'm currently working on an educational Flash application on the Adobe CS5 Flash Professional platform, using the ActionScript 3 programming language.
In my program the user is required to plot a shape onto a 4x4 squared grid, which I’ve generated using a For Loop that runs through sixteen times.
As the For Loop constructs the grid, it adds 16 child instances of the same 23x23 pixel squared MovieClip, laid out equally in four rows and four columns and each of these MovieClip is assigned a unique ID number ranging from 1-16 and a Mouse Down listener event, ready for user interaction.
Should the user click on a square in the grid, during the course of plotting and selecting their shape, the MovieClip’s colour will firstly change to signify to the user it has been selected for inclusion.
Secondly I’ve also set-up a Boolean based Array [0-15], which links to the corresponding ID numbers of the grid, so for example if I selected the top left square in my 4x4 grid, the [0] property of my Boolean array would change from false to true and likewise if I selected the third square along on the second row of my grid the [6] property of my array would do the same and so on.
Now using this technique and referencing the array, I can always know which blocks have been chosen by my user and by running another For Loop on a subsequent slide in my program, I’ve managed to output, based on my ‘selection’ Boolean array, the same shape that my user has designed, in the confines of another 4x4 grid, with the selected blocks colour changed from grey to black, if any array value is set to True.
Now my problem is that my user will subsequently need to plot their designed shape, produced on the first grid, onto a larger second grid in large volumes (up to 8-9 times on some occasions). This grid is considerably larger than 4x4 one, being 24 x 12 to be exact (288 blocks).
Now what I need is when my user clicks on this second larger grid I want an output of their designed shape to be added to the stage as a brand new MovieClip.
But importantly the shape needs to be cropped down. For example if the user made a square shape on the first grid by selecting blocks 2,3,6,7; I don’t want a 16 block MovieClip (92x92 pixels, based on my 23x23 pixel blocks) being added to the bigger grid with four blocks shaded a different colour, I want a 4 block, squared shape (46 x 46 pixels, based on my 23x23 blocks) to be added, from the top-left grid square you select on the second grid.
Ideally I’d like to create my user’s plotted shape programmatically using the Shape Drawing tool and do this within a function, so I can then run the function each time the user enters the second grid area and update the user’s shape, should the user had gone back and amended it in the first grid. This would also give me the scope to also change the shape colour prior to adding the child of it to my stage, which is another area of functionality I need and another reason why I’d like to do this shape programmatically.
I imagine capturing the x/y co-ordinates of the blocks from the first grid in a further array and subsequently searching through that array to find the first block instance and then draw the shape from this point, could be the way forward but that is as far as my thinking has taken me.
Any ideas or suggested reading on how to do this would be very welcome. Many Thanks.
My suggestion is that you use bitmaps as your base class for such a shape, initialize it with full transparence, then draw() your MCs on that bitmap.bitmapData with adjusted X&Y values, then you place that bitmap over your "larger grid" using supplied X&Y.
var bd:BitmapData=new BitmapData(23*4,23*4,true,0x0);
var mat:Matrix=new Matrix();
mat.tx=-1*LeftCornerX;
mat.ty=-1*LeftCornerY;
for (i=0;i<16;i++) if (BlockMCsSelected[i]) bd.draw(BlockMCs[i],mat);
var bm:Bitmap=new Bitmap(bd);
bm.x=SuppliedX;
bm.y=SuppliedY;
LargerGrid.addChild(bm);
Basically, this should do if you specify your input data correctly. But if you need it to receive events, encapsulate this bitmap into a Sprite object, that one can process events, and give coordinates to sprite, not bitmap.
I want to visualize a scatter plot using Prefuse. The difference from typical scatter plot is here I want to use rectangle instead of circle or point. And the reason is I want to visualize the time and duration at the same time. Does anyone know how to set rectangle's length or width according to data in the table? I haven't got the right answer after searching the web.
I initially wants to draw rectangle using this parameter.
ShapeAction shape = new ShapeAction(group, Constants.SHAPE_RECTANGLE);
But I didn't find the way to change only the length of it but to change the whole size. Could anyone give me some instructions? Thanks.
Assuming you want to create a visualization similar to LifeLines or a GANTT chart.
To achive this, prefuse has to be extended prefuse on several points. Here is an outline:
Add a field to the VisualTable to store the x coordinate at the end of the rectangle
Extend AxisLayout to determine the additionally the end of the rectangle.
Extend AbstractShapeRenderer draw a rectangle using the end coordinate
Same as the question:
I need to drag a component along a programmatically drawn path composed by different kinds of graphic, like lines, curves, etc.
I've already googled it, but with no success.
Any ideas? thanks!
The following is say for a linearly curved path drawn by you. You can use similar method for any direction.
Add an Event listener for click.
(That starts drag)
Track the user's mouse along x
direction for example.
Keep plotting the component's x & y as
Mouse x changes with respect to the
drawn path's x.
Stop relocating as user leaves the
mouse
Start with this if possible & be back with code if you get doubts.
If your drawing part is complete then You can use two dimensional ByteArray. The size of the ByteArray will be the size of your stage, this two-dimensional array will be set to zero, means all your stage locations are set to zero. When any curve or line is drawn , set those locations to one. Now you know at-least where your object can move, the valid locations are those which are set to one.
Now the second the part is how to move an object on the valid path or location using mouse or keyboard.
You will be using Event.EnterFrame for smooth and fast movement of the object,
1--using keyboard.
use up key to move object to upper location if that position or location is set to one else the object will not move Up, same for others.
2-- using mouse move event, detect MouseY position for moving UP or DOWN w.r.t current position of MouseY , and move it respectively if location is set to one.
Hope, this will guide you in right direction...
Will this work? http://www.pixeldigest.com/followthepath.html
To clarify things, what i am trying to do is to get the openGL coordinates and manipulate them in my mfc code. not to get an openGL object. i'm using the mfc to control the position of the objects in the openGL.
Hi, i'm trying to find the naswer on the web and can't find a full solution that i can use and that will work...
I'm developing a MFC project with static picture as the canvas for an openGL class that draw the grphics for my game.
On moush down, i need to retrive a shape coordinate from the openGL class.
I'm looking for a way to convert the openGL coordinates to MFC coordinates but no matter what i try i get junk after using the gluProject or gluUnProject (i've tried to do both ways but non is working)
GLdouble modelMatrix[16];
glGetDoublev(GL_MODELVIEW_MATRIX,modelMatrix);
GLdouble projMatrix[16];
glGetDoublev(GL_PROJECTION_MATRIX,projMatrix);
int viewport[4];
glGetIntegerv(GL_VIEWPORT,viewport);
POINT mouse; // Stores The X And Y Coords For The Current Mouse Position
GetCursorPos(&mouse); // Gets The Current Cursor Coordinates (Mouse Coordinates)
ScreenToClient(hWnd, &mouse);
GLdouble winX, winY, winZ; // Holds Our X, Y and Z Coordinates
winX; = (float)point.x; // Holds The Mouse X Coordinate
winY; = (float)point.y; // Holds The Mouse Y Coordinate
winY = (float)viewport[3] - winY;
glReadPixels(winX, winY, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &winZ);
GLdouble posX=s1->getPosX(), posY=s1->getPosY(), posZ=s1->getPosZ(); // Hold The Final Values
gluUnProject( winX, winY, winZ, modelMatrix, projMatrix, viewport, &posX, &posY, &posZ);
gluProject(posX, posY, posZ, modelMatrix, projMatrix, viewport, &winX, &winY, &winZ);
This is just part of the code i've tried. ofcourse not gluProject and gluUnProject together. just had them both here to show.....and i know there is lots of junk over there, its from some of my tries...
p.s. i've tried many many more combinations and examples from the web and nothing seem to work in my case....
Can any one show me what is the right way to do the transformation?
10x
It looks like you're trying to retrieve the object (or objects) that is/are at a particular point. If this is the case, gluProject and/or gluUnProject isn't really a very suitable tool for the task. OpenGL has a selection mode intended specifically for this kind of task.
In typical use, you specify a small square (e.g., 5x5 pixels) around the mouse click spot with gluPickMatrix, set selection mode with glRenderMode, set a buffer with glSwelectBuffer, and then draw your scene. The drawing doesn't go to the screen, but fills the buffer you specified wiyh records of what was drawn within the specified area.