I am designing a minesweeper kind of layout for a game in silverlight. Currently, I have used a square user control on the Canvas control. There are properties assigned to it.
I also want to add a functionality at a later stage. It is about curving using the bezier curves and plotting those squares on the curve with the x,y co-ordinates instead of looping through. Then I want to send the square's x,y position in an XML file.
My question is that what way should I use that will be the best optimized combination in terms of least memory consumption, fast and efficient performance as well as easy implementation.
If you experts have any other ideas, please let me know.
Thanks in advance.!
If you can draw everything as shapes and images (i.e. vector graphics) and you'll be able to take advantage of the hardware acceleration for the graphical elements. Also, you'll get better performance if you don't define your squares as UserControls, you should be creating them dynamically in code as shapes containing other shapes and then have an object model that is linked to the shapes based on their position (e.g. Dictionary squares; Dictionary squareElements).
In terms of memory consumption and file access you should keep the square's x,y position in memory as a Point strucutre and serialize to file (XML is fine) only when you need to (i.e. when the player leaves the game).
Well, over the days, I sorted out the answer myself. I continued through my Square user control and used it in the layout.
About plotting of the x/y positions, I used this:
Point point = myElement.TransformToVisual(App.Current.RootVisual as FrameworkElement)).Transform(new Point(0, 0));
There was a glitch in saving XML file because silverlight 4 does not give elevated privileges for in-browser application. But then I used this on my save button click event:
SaveFileDialog dlgSave = new SaveFileDialog();
dlgSave.DefaultExt = "xml";
dlgSave.Filter = "XML Files (XML)|*.xml;";
dlgSave.FilterIndex = 1;
strXML = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + myXML.ToString();//myXML is the XDocument I created globally and saved data in it
try
{
bool check = (bool)dlgSave.ShowDialog();
if (check)
{
using (Stream stream = dlgSave.OpenFile())
{
StreamWriter sw = new StreamWriter(stream, System.Text.Encoding.UTF8);
sw.Write(strXML);
sw.Close();
stream.Close();
}
MessageBox.Show("XML Saved successfully");
}
catch (SecurityException)
{
MessageBox.Show("There seems to be an issue with saving XML file on the disk, please try again...", "Something's not right", MessageBoxButton.OK);
}
catch (UnauthorizedAccessException)
{
MessageBox.Show("Saving here requires authorised permissions", "Access Denied", MessageBoxButton.OK);
}
Related
So i was trying to create a location display buffer which isn't available in scene map, so for this
i created a triangle symbol and updated it so that every time location changed the graphic has to be erased and placed at new position like this
prevLocX=camera.location.X// initialized at start
prevLocY=camera.location.Y
newLocX=camera.location.X
newLocY=camera.location.Y
callCurrentLocation();
CallCurrentLocation()
{
if prevlocX!=newlocX && ...
{
go.Graphics.Clear();
Mappoint mp1=new Mappoint(newLocX,newLocY,SpatialReferences.wgs84);
--
--
go.graphics.add(msm1);
PrevlocX=newLocX;
PrevLocY=newLocY;
}
i know this seems redundant and inefficient but this was the best way i could think of please see if it can be made better
Most efficient would be to keep the overlay and graphic instances and just update the geometry on the graphic with a new point each time.
I have this project:
my codepen
I want to be able to move forward when the user walks, so it feels like they are walking thru the floor plan in VR as they are in real life.
my goal is get the geolocation of the user and show them the room matching theirs location and have them walk around the room while viewing the AR on the phone they would see paintings on the walls.
my challenges are:
walk in real life and move in VR (right now I have it auto walking forward in the meantime)
var speed = 0.0;
var iMoving = false;
var velocityDelta;
AFRAME.registerComponent("automove-controls", {
init: function() {
this.speed = 0.1;
this.isMoving = true;
this.velocityDelta = new THREE.Vector3();
},
isVelocityActive: function() {
return this.isMoving;
},
getVelocityDelta: function() {
this.velocityDelta.z = this.isMoving ? -this.speed : 0;
return this.velocityDelta.clone();
}
});
capture the user geo location so the moment they open the site they are placed relative to their location on the floor plan
this is my first attempt so any feed back would be appreciated.
As far as i know argon.js is more about geoposition than spatial/marker based augmented reality.
moreover It's quite worrying, that their repo for aframe was not touched for a while.
Argon seems like a library for creating scenes in certain points around the user, even their examples base on positioning stuff around, reason being the GPS/phone accelerometers are way too bad to provide useful data for providing spatial positioning. Thats why VIVE needs two towers, and other devices at least a camera/IR device, to get information about the HMD device.
Positioning the person inside a point depending where are they in a room is quite a difficult task, You would need to get a point of reference and position the user accordingly. It seems impossible, since the user can be anywhere in the world.
I would try to do this using jerome-etienne's marker based AR.js. The markers would be the points of reference You need, and although image processing seems like a difficult task, AR.js is surprisingly stable with multiple markers, which help in creating complex scenes.
The markers seems like a good idea, for they can help You with the positioning, moreover simple scenes have no problem with achieving 60+fps, making the experience quite comfortable.
I would start there, since AR.js seems to be updated frequently.
Using paper.js and loving it. I want to use the Cartesian coordinate system though, as opposed to the "document"-style system that is default.
When I draw on a canvas with plain js (without paper.js), I enforce the transformation like this (on $(document).ready()):
ctx = canvas.getContext("2d");
ctx.scale(1, -1);
ctx.translate(0, (-canvas.height/2));
But with the way paper.js runs in the browser, this doesn't work.
The view object in paper has a method transform(), yet the following code throws an error, even though the view object is clearly available by the output to the console:
console.log(view);
view.transform( new Matrix(1,0,0,-1,300,300) );
// console output:
// CanvasView {_context: CanvasRenderingContext2D, _eventCou......
// Uncaught TypeError: view.transform is not a function
I'm thinking I need to call transform upon some document load event? But I don't see any straightforward events such that in paper's API.
Is there a simple way to just simply apply a linear transformation to the whole view once, in the beginning, to get a Cartesian system?
Figured out the following works:
project.activeLayer.transform( new Matrix(1,0,0,-1,view.center.x, view.center.y) );
I'm trying to load an SWF into another in AS3/Haxe. The loaded SWF contains some images - but only on some Shape.graphics elements. (Like graphics.beginBitmapFill(); ...)
This images are not smoothed, and jaggy.
Can this images be smoothed anyhow during runtime?
Any hack interested! :)
Thanks in advance!
Tom
Update: Sorry, but I forget to mention, that I'm loading more AS2-SWFs (AVM1) into one AS3-SWF (AVM2) with AVM2Loader, which hack the loaded bytes, and convert the AVM1 SWFs into AVM2 - it works very well. :)
So, in these SWFs I need to find the images/bitmaps, but only found the Shapes, which graphics elements has the 'images'. If I clear this graphics, then all images are gone, so I think, the images are in some graphics.beginBitmapFill(...);, without smoothing. I want to reach them, and switch smoothing on at runtime, if possible.
(Sorry, if the first time I was not enough clear.)
Edit (Jan 23 '14): I found solution for it. It is not fast, and required Flash Player 11.6. Every MovieClip graphics properties has a new readGraphicsData function, which give all the graphics commands (Vector IGraphicsData) to draw the whole MC. And iterate in these commands, if I change every bitmapFill command smooth parameter to true, and redraw the MC, it will be smoothed, and nice.
That's it. Not fast, but working.
I found solution for it. It is not fast, and required Flash Player 11.6. Every MovieClip graphics properties has a new readGraphicsData function, which give all the graphics commands (Vector IGraphicsData) to draw the whole MC. And iterate in these commands, if I change every bitmapFill command smooth parameter to true, and redraw the MC, it will be smoothed, and nice.
That's it. Not fast, but working.
function onLoad(event):Void
{
pic.forceSmoothing = true;
}
Smoothing is a property of bitmaps that's off by default.
var image = new Bitmap(bitmapData);
image.smoothing = true;
Typically, your bitmapData will be in the loader.content.bitmapData when loading externally, but it's up to you were you've stored it.
Update:
If you want to smooth all images in a loaded SWF without any knowledge of the structure of the SWF, then you'll have to recursively dig through the hiarchy of that SWF, and depending on whether or not the object is a Bitmap, turn on smoothing.
function recursivelySmooth(obj):void {
for (var i:int = 0; obj.getChildAt(i); i++) {
var item:* = obj.getChildAt(i);
if (item is Bitmap) {
item.smoothing = true;
} else if (item.hasOwnProperty("numChildren") == true) {
recursivelySmooth(item);
}
}
}
This was written freehand, so you may have to doublecheck everything is correct, but that's the basic idea. Just call recursivelySmooth() on your swf, and it'll dig through all objects that can have child elements and smooth them.
I am designing a Windows Phone 7 project where I need to determine position changes of the device. I tried to use accelerometer, but it gives info on current orientation of my phone and I don't know how to convert this data to position delta. Here is some example code:
void acc_CurrentValueChanged(object sender, SensorReadingEventArgs<AccelerometerReading> e)
{
AccelerometerReading newdata = e.SensorReading;
Vector3 vect = newdata.Acceleration - data.Acceleration;
//what comes here???
}
The method above is called when accelerometer data is changed. But I don't know how to convert this data to position change of a device (i.e. I move my phone in X direction)
You can't do it.
You get position by integrating the linear acceleration twice but the error is horrible. It is useless in practice.
See the above linked answer to get some ideas what you actually can do.