How to specify the initial position of a 2D object like rectangle in Spark AR? - spark-ar-studio

I have a 2d object (rectangle0), for which I have created a Screen Pan patch, which is used to change the position of the object. But the problem I am facing is how to set the initial position for the 2d object, it is currently being set to (0,0) so the object is in the center of the screen, but I want it somewhere else.

First, check if the Screen Pan "State" is active. When the effect loads it will not be active. Use an If Then patch to set an initial value if the state is not active. Once active, then use values from Screen Pan.
I have a Drag 2D patch you can download to simplify the process of handling 2D objects. You can set the default position with this patch.

Related

Constrain facemesh to 3D object in SparkAR

I am trying to constrain a facemesh to a 3D object so that it will rotate around the surface of the 3D object in response to the face tracker instead of moving off to the side. Currently, the facemesh is a child of the cylinder, but is not attached to it in a way that would rotate around the cylinder surface.
Currently, I am attempting to use the bounding box patch to determine the area to clamp the face mesh to. So far, the mesh is related to the 3D object bounding box, but will not constrain to its surface. Adjustment to the clamp patch variables will move the face mesh within the space, but not constrain it either.
The answer is much simpler than I first attempted. Using the patch editor:
Unpack the 3D rotation from the facefinder.
take the from range from the X and Y positions
look at the maximum and minimum ranges of the face tracker rotation/position values to set To and From Ranges
create a null object and make it a child of the stationary 3D object
make the face mesh a child of the null object
connect the output of the face tracker's rotation/position to the rotation/position value of the null object.

Adobe Flash/Animate - transformation point equivalent in Actionscript 3

When you're using the Flash/Animate IDE and you select something on the stage with the Free Transform Tool, then move the transformation point (the white circle), what is it actually doing in frame script? DisplayObjects only have x and y properties, there's no transformX or transformY.
I have a MovieClip place on the stage through the Flash IDE with various transformations applied to it, and I would like to be able to replicate those in Actionscript.
When you're creating a display object in IDE, moving transformation point makes IDE move everything inside that object in reverse direction coordinates wise. It's like if you're moving a zero point of a local coordinates system, leaving everything else intact, the contents will then have their coordinates altered.
In order to simulate this behavior, you can nest your display object being created into a container sprite, then when your user drags transformation center, you move the wrapper sprite to the new coordinates and alter its nested object's ( the one with all the contents) coordinates by negative delta between old and new positions of virtual zero.

As3 change object width/height, then set new size scale as 1

I have an object manipulation function that(right now) manipulates the scale of the objects inside of an array to give real-time size changes in relation with each other.
What I would like to know is if there's a way to change an object's width/height(to fit the screen size since it's a mobile app) and then reset the scale so that the new width/height has a scaleX/scaleY value of 1.
The width/height are properties that directly influence the scale of a DisplayObject. You cannot resize it without affecting the scale.
You can however:
Draw the image as bitmap
Redraw it if it's a primitive
Put it in a holder
A little about every solution:
Drawing a DisplayObject (or any IBitmapDrawable) is done through creating a BitmapData and using a draw() call. The up-side is that it will be a bitmap and thus save some rendering time. The downside is that if it's a large image it will take memory (can be critical for mobile) and it won't have interactivity/animation unless you make a script that would read the animation.
If you're drawing the element though the Graphics class's API, you might just make something like a resize() method that you would call on window resize/flip-orientation. Just utilise the clear() method of the Graphics object and redraw the whole thing.
Lastly, probably your best pick. Resize your object. Make a new Sprite (I choose Sprite because it's interactive and you probably want that) and add the resized object to that newly made sprite while the Sprite is just added to the display list like you added the resized object before. If it's hard to understand, here's some code:
myResizeableObject.width = newWidth;
myResizeableObject.scaleY = newScaleY;
var holderSprite:Sprite = new Sprite();
myResizeableObject.parent.addChild(holderSprite); // if you don't have a specific place to add the myResizeableObject, don't use myResizeableObject.parent - it's ugly
holderSprite.addChild(myResizeableObject);
Hope that helps you!

Dragging an object along a drawn path

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

Trying to convert openGL to MFC coordinates and having Problems with "gluProject"

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.