I am new to spark AR, I have seen the documentation but unable to find support where you can achieve below queries.
Zoom in and zoom out camera towards a 3D object
Rotate around a 3D object
It says camera coordinates are read only, you cannot change its position on an event.
Any pointers or insights on this guys?
Thanks
No, you cannot move the actual camera in Spark, because that is mapped to the device camera position (aka your phone).
However, if you wish to scale the video feed, you could get the camera extract texture, apply it as a material to a canvas or plane, and then scale the plane in order to create a "zoom" effect.
You can also rotate and move 3d objects by editing their transform properties, like so:
let myObj = Scene.root.find('my-object');
myObj.transform.x = value;
myObj.transform.y = value;
myObj.transform.z = value;
myObj.transform.rotationX = value;
myObj.transform.rotationY = value;
myObj.transform.rotationZ = value;
myObj.transform.scaleX = value;
myObj.transform.scaleY = value;
myObj.transform.scaleZ = value;
etc.
Related
I can not zoom in the current location of the device, could someone help me?
any help is welcome.
override fun onMapReady(googleMap: GoogleMap) {
Log.i("MAP READY", "READY")
val position = if (currentLocation != null) LatLng(currentLocation!!.latitude, currentLocation!!.longitude) else null
this.map = googleMap
getFineLocationPermission()
this.map!!.setOnMarkerClickListener(this)
this.map!!.uiSettings.isRotateGesturesEnabled = true
this.map!!.uiSettings.isZoomGesturesEnabled = true
this.map!!.setOnInfoWindowClickListener(this)
this.map!!.setOnMapLongClickListener(this)
}
Generally, you can change a map's zoom level by changing its camera position. According to this documentation:
To change the position of the camera, you must specify where you want to move the camera, using a CameraUpdate. The Maps API allows you to create many different types of CameraUpdate using CameraUpdateFactory.
Since you did not provide your full code, let me insert samples below:
If you want to keep all other maps properties to be the same and just change the zoom level, you can use this line:
//where zoomLevel is your preferred zoom level
mMap.moveCamera(CameraUpdateFactory.zoomTo(zoomLevel))
If you want to zoom a map on the location where the marker was placed, then below your addMarker() function, you can add this line to zoom your map on a City level:
// zoomLevel is set at 10 for a City-level view
val zoomLevel = 10
// latLng contains the coordinates where the marker is added
mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(latLng,zoomLevel))
Fun tip: You can animate the camera view update if you use animateCamera() instead of using moveCamera()
For more information on Maps SDK for Android - Camera and View settings, please see https://developers.google.com/maps/documentation/android-sdk/views
Better you can optimize your code
override fun onMapReady(googleMap: GoogleMap) {
Log.i("MAP READY", "READY")
val position = if (currentLocation != null) LatLng(currentLocation!!.latitude,
currentLocation!!.longitude) else null
this.map = googleMap
getFineLocationPermission()
this.map?.let{
it.setOnMarkerClickListener(this)
it.uiSettings.isRotateGesturesEnabled = true
it.uiSettings.isZoomGesturesEnabled = true
it.setOnInfoWindowClickListener(this)
it.setOnMapLongClickListener(this)
//zooming into the map
it.moveCamera(CameraUpdateFactory.newLatLngZoom(currentLocation,zoomLevel))
}
I have a map that is set up in createjs with a responsive canvas. What I am trying to do is make the map zoomable but also dragable. When the map is dragged I would like to have it zoom from a specific center point.
What I think I need to do is calculate the position of the of the center point relative to the map and then set the maps regX/regY to that point(I then think I need to reset to x/y of the map to make up for the regX/Y offset.
Since the stage is scaled I'm having a hard time even figuring out the center locations because the global coordinates seem to chance with the scaling. I've put the center point in a holder:
exportRoot.pointHolder.tmpPt
and the map is contained in:
exportRoot.map_main_sym
what I need to figure out is what is the map_main_sym local x/y value relativie(ie directly under (exportRoot.pointHolder.tmpPt.x , exportRoot.pointHolder.tmpPt.y)
I don't recommend changing the registration point when zooming. A better approach is to determine the distance from your mouse, and determine how much to translate the container/object when you scale it.
Here is a snippet from a map tool I had handy:
// Find the mouse point INSIDE the mapView
var point = new createjs.Point(this.stage.mouseX, this.stage.mouseY);
var localPoint = this.mapView.globalToLocal(point.x, point.y);
// Scale the Map View
if(event.wheelDeltaY > 0){ // This is part of a mousewheel event
// zoom in
this.mapView.scaleX = this.mapView.scaleY *= 1.3;
} else {
this.mapView.scaleX = this.mapView.scaleY /= 1.3;
}
// Find where the original point is now
var globalPoint = this.mapView.localToGlobal(localPoint.x, localPoint.y);
// Move the map by the difference
this.mapView.x -= (globalPoint.x - point.x);
this.mapView.y -= (globalPoint.y - point.y);
This is just an example, I am sure there is a more pure math approach.
Cheers.
Hello i try to texture a sphere with a png but it apply the texture wrong and messes it up.
i cant find any way to move it around and play with the texture/material untill it will be set correctly.
i want to create a soccer ball and to apply it a ball texture
This is my code i use to create the material and apply it
Thanks
[Embed(source=”../assets/Ball.png”)]
public static var TheBallTextureClass:Class;
public var TheBallMaterial:TextureMaterial;
var theball:Mesh;
TheBallTexture = new BitmapTexture(new TheBallTextureClass().bitmapData);
TheBallMaterial = new TextureMaterial(Cast.bitmapTexture(TheBallTexture));
TheBallMaterial.smooth = true;
TheBallMaterial.repeat = true;
theball = new Mesh(new SphereGeometry(30), _ballMaterial);
That's because the UV Mapping of the SphereGeometry is weird and is not made for a pattern like the soccer ball.
I suggest you to create the sphere in 3ds max and unwrap it there.
EDIT:
If you want you can edit UV mapping of SphereGeometry inside Away3D:
Create a SubClass of SphereGeometry and override "buildUVs(target:CompactSubGeometry)" creating your own set of UVs.
I've got a big issue and it's almost a week trying to make it work so any help I would really appreciate - I am trying to create a simple image editor in html5, so I upload an image, load it into canvas and then paint on it -
I also want to be able to zoom in and zoom out- just that I can't figure out how should I save the canvas state - for the paint mouseevents I am using an array which saves canvas.toDataUrl, but this one will save only what it is visible in canvas, only a part of the scaled image, and not the entire one -
if anyone knows how can I un-scale the canvas together with the painting over it and save it in the stack from where I can retrieve it for other painting events, I'll appreciate a lot! Thanks
Saving state
The canvas' save() and restore() is not related to the pixels in the canvas at all. Save() only saves current pen color, fill color, transform, scale, rotation and so forth - parameter values only, not actual pixel data.
And so, the restore() will only restore these parameter values to the previous ones.
The canvas element is passive, meaning it only holds the pixels that you see on the screen. It does not keep a backup of anything so if you change its size, re-size browser window or open dialogs in the browser causing it to clear, you will need to update the canvas yourself.
This also applies when you change a parameter value such as scale. Nothing on the canvas will change setting a new value. The only thing that happens is that your next draw of what-ever will use these parameter values for the drawing (in other words: if you apply rotation nothing rotates, but the next thing you draw will be rotated).
Drawing on existing image
As you need to maintain the content it also means you need to store the image you draw on as well as what you draw.
When you draw for example lines you need to record every stroke to arrays. When the canvas needs an update (ie. zoom) you redraw the original image first at the new scale, then iterate through the arrays with lines and re-render them too.
Same for points, rectangles, circles and what have you..
Think of canvas as just a snapshot of what you have stored elsewhere (image object, arrays, objects) . Canvas is just a view-port for that data.
I would recommend to store as this:
var backgroundImage; //reference to your uploaded image
var renderStack = []; //stores all drawing objects (see below)
//example generic object to hold strokes, shapes etc.
function renderObject() {
this.type = 'stroke'; //or rectangle, or circle, or dot, ...
this.x1;
this.y1;
this.x2;
this.y2;
this.radius;
this.penWidth;
this.penColor;
this.fillColor;
this.points = [];
//... extend as you need or use separate object for each type
}
When you then draw a stroke (pseudo):
var currentRenderObject;
function mouseDown(e) {
//get a new render object for new shape/line etc.
currentRenderObject = new renderObject();
//get type from your selected tool
currentRenderObject.type = 'stroke'; //for example
//do the normal draw operations, mouse position etc.
x =..., y = ...
}
function mouseMove(e) {
//get mouse positions, draw as normal
x = ..., y = ...
//store the points to the array, here:
//we have a line or stroke, so we push the
//values to ourpoint-array in the renderObject
currentRenderObject.points.push(x);
currentRenderObject.points.push(y);
}
function mouseUp(e) {
//when paint is done, push the current renderObject
//to our render stack
renderStack.push(currentRenderObject);
}
Now you can make a redraw function:
function redraw() {
clearCanvas();
drawBackgroundImage();
for(var i = 0, ro; ro = renderStack[i]; i++) {
switch(ro.type) {
case 'stroke':
//... parse through point list
break;
case 'rectangle':
//... draw rectangle
break;
...
}
}
}
function zoom(factor) {
//set new zoom, position (scale/translate if you don't
//want to do it manually). Remember that mouse coords need
//to be recalculated as well to match the zoom factor.
redraw();
}
//when canvas is scaled for some reason, or the window
canvas.onresize = windows.onresize = redraw;
A bonus doing this here is you can use your render stack as a undo/redo stack as well...
Hope this helped to better understand how canvas works.
I have a display object (not image) that I'm scaling down. It has the same jaggies and aliased edges that an image does when it's scaled. Is there a way to smooth that display object in the same way the image is smoothed?
Update
This is an interactive display object (sprite) with interactive child display objects. I can't draw it to a bitmap.
You can try forcing the display object into "3d" mode by adding a Matrix3D transform to it. The easiest way to do that is to simply give it a rotationX value:
myDisplayObject.rotationX = 0.0;
You can also try checking the "hinting" box on your shapes (sometimes this makes circles & ovals get sort of strange shaped, so it's a gamble), and you can try selecting "Cache as bitmap" from the render dropdown.
Do bicubic resampling on the sprite with Pixel Blender?
http://blog.onthewings.net/2009/08/25/bicubic-resampling-by-pixel-bender/
You can try to set the smoothed property of the bitmap object to true and than scale it:
look here
You Display object must contain a Bitmap, or is the Bitmap itself...
Have you tried setting stage.quality = stageQuality.High;?
Also if you did that and you want to set the smoothing manually you can try the Lanczos re-sampling function (I did not made it).
Warning: you don't want to use this function every frame since it's pretty performance heavy!
First you need to draw you displayObject to an Bitmap with BitmapData:
var bmd:BitmapData = new BitmapData(dispObject.width, dispObject.height, true, 0);
//Create new bitmapData with the same size as your object and with transparancy.
bmd.draw(dispObject);
//Draw you displayObject onto the empty Bitmap
var b:Bitmap = new Bitmap(bmd, true);
//Create the bitmap container and load the data, and the true turns smoothing on!
addChild(b);
//Add it to the stage and now you can use the scale and width variables like this
b.x = dispObject.x;
b.y = dispObject.y;
b.scaleX = dispObject.scaleX;
b.scaleY = dispObject.scaleY;