Hello I am trying to increase the zoom of the camera to its max level in my application.
However after setting the AvCapture to its max value it remains at its lowest zoom level on the screen. Below is my code.
void Initialize()
{
var videoDevices = AVCaptureDevice.DevicesWithMediaType(AVMediaType.Video);
var cameraPosition = (cameraOptions == CameraOptions.Front) ? AVCaptureDevicePosition.Front : AVCaptureDevicePosition.Back;
var device = videoDevices.FirstOrDefault(d => d.Position == cameraPosition);
device.LockForConfiguration(out error);
if (error == null)
{
Console.WriteLine("Supports Preset");
var test = device.RampingVideoZoom;
var d = device.VideoZoomFactor;
device.VideoZoomFactor = device.ActiveFormat.VideoMaxZoomFactor;
}
device.UnlockForConfiguration();
while(device.RampingVideoZoom == true)
{
Console.WriteLine("Zooming camera"); //This line is never written
}
//See below for value this returns in Console
Console.WriteLine("Current Format");
Console.WriteLine(device.ActiveFormat);
}
Current Format
<AVCaptureDeviceFormat: 0x1c48049a0 'vide'/'420v' 1920x1080, { 3- 30 fps}, HRSI:4096x2304, fov:59.680, supports vis, max zoom:16.00 (upscales #1.94), AF System:2, ISO:22.0-704.0, SS:0.000005-0.333333>
This code does not affect the zoom of the camera AT ALL.
What am I doing wrong?
videoMaxZoomFactor Definition
A maximum factor of 1.0 indicates that the format is not capable of zooming.
There is no mistake in your code.
As the Documentation said ,if device.ActiveFormat.VideoMaxZoomFactor == 1 ,the zoom is not available.
You can debug the value of device.ActiveFormat.VideoMaxZoomFactor to see if it euqals to 1.
Related
I want to know is it necessary to set application frame rate in Unity's android game script?
What is the best frame rate for android ? 30 fps or 60 fps ?
What if we do not set it? is it affect on game performance ?
Because my game has lag in some devices and it's genre is First Person Shooter.
Could it be because I did not specify the frame rate of the game?
Because I've been optimizing my game scripts as far as I can.
And in unity's profiller I checked my scripts and i didn't see any serious problem.
But some time's I have lag when i turning around. I mean when player looks around, some times he rotate about 180 degree or more quickly when lag is happening.
Here is part of my mouse look code :
void Update()
{
the_time = Time.deltaTime;
if (Input.touches.Length > 0)
{
foreach (Touch t in Input.touches)
{
if (t.position.x > Screen.width / 2)
{
if (t.phase == TouchPhase.Began)
{
delta = t.deltaPosition;
}
if (t.phase == TouchPhase.Began || t.phase == TouchPhase.Moved)
{
delta = -t.deltaPosition;
rotX += (delta.y * sensitivityX * current_speed_offset_vertical * the_time);
rotY -= delta.x * sensitivityY * current_speed_offset * the_time;
rotX = Mathf.Clamp(rotX, -clampAngle, clampAngle);
TlocalEurlar.y = rotY;
transform.eulerAngles = TlocalEurlar;
x_rot_transform_Eurlar.x = rotX;
x_rot_transform.localEulerAngles = x_rot_transform_Eurlar;
}
else if (t.phase == TouchPhase.Ended)
{
delta = t.deltaPosition;
}
}
}
}
}
Is there a problem with my script?
Can this problem be related to not setting the frame rate of the game?
I want to setup kendoNumericTextBox to allow user input any integer number and set step to 1000. But when user enters any value and use spinner, it should update to next multiple of step.
For example:
enter 123, press spin up, value will be 1000
enter 1234, press spin up, value vill be 2000
Is it possible or only way is to handle spin event and modify value from there?
UPDATE:
Ok, guys, thnx for help.
I have this spin handler now and it seems to be working as expected.
function onSpin(e)
{
var currentvalue = kendo.parseInt(this.value());
if (currentvalue > 0)
{
this.value(Math.floor(currentvalue / this.step()) * this.step());
}
if (currentvalue < 0)
{
this.value(Math.ceil(currentvalue / this.step()) * this.step());
}
}
I have provided a dojo below with a potential solution for you:
https://dojo.telerik.com/UQohUjaP/2
I have created a function that will work on the spin and on change value so that it will step the value up/down on the value that you set e.g. 1000
the function is fairly simple and for brevity I have taken out the log statements here:
function onChange() {
var currentvalue = kendo.parseInt(this.value());
if (currentvalue > 0) {
currentvalue = Math.ceil(currentvalue / this.step()) * this.step();
} else if (currentvalue < 0) {
currentvalue = Math.floor(currentvalue / this.step()) * this.step();
} else {
currentvalue = 0;
}
this.value(currentvalue);
}
Unfortunately there doesn't seem to be a simple way of figuring out if the value has gone up or down so I am basically checking to see if the value is greater than 1 or less than 1 and then calculating the ceiling or the floor for the value and then stepping it in the right direction. in order to cater for zero we have a special condition which just sets the value to 0 assuming that is a valid value in your scenario
As you say, it's possible by listening to the spin event:
$("#numerictextbox").kendoNumericTextBox({
min: 0,
spin: function(e) {
var isUp = e.sender._key === 38,
isDown = e.sender._key === 40;
var m = Math.trunc(this.value()/1000),
value = isUp ? m + 1 : m;
this.value(value * 1000);
}
});
I doubt there's something out of the box, because your needs seem somewhat unusual.
I'm struggling on how I can put this into code.
int a=500;
By default x = a-100
I am trying to find a way where when one button is clicked, it sets the x-coordinate to x=a-100 , and then when the same button is pressed again, it sets x=0.
How would i logically put this into code?
Thanks a lot!
Somewhere, have a variable keep track of whether or not the button has been previously pressed. Since you haven't indicated what language you're using, I'll have to make this very generic, and assume the typical interface that's used to handle button press events.
var button = (some GUI button object);
var a = 500;
var x = 2;
var buttonHasBeenPressed = false;
button.onPress = function() {
if (buttonHasBeenPressed) {
x = 0;
} else {
x = a - 100;
}
buttonHasBeenPressed = true;
};
Where you store the flag (buttonHasBeenPressed) depends on your skill level, the size of your program and many other factors. This is just a rough example using pseudo-javascript.
I do a growth animation of a fixed number of items, and after growth, i moved it to left.
Make growth by apply matrix
var trans_vector = new THREE.Matrix4().makeTranslation(0, height / 2, 0);
var graphics = new Graphics();
var rectangle = graphics.box(width, height, material);
rectangle.geometry.applyMatrix(trans_vector);
When a new item is added, i remove one from the container that will be added to scene
var children = this.container.children;
if (this.current_number === this.max_number) {
this.container.remove(children[0]);
this.current_number = this.max_number - 1;
}
object.position.copy(this.position); // this is a fixed position
this.container.add(object);
this.current_number++;
I write a function to translate to left, using tweenjs (sole)
animateTranslation : function(object, padding, duration) {
var new_x = object.position.x - padding; // Move to left
console.log(new_x); // Duplicated item here :(
new TWEEN.Tween(object.position).to({
x : new_x
}, duration).start();
},
And I remove all the "previous" items, using for loop
for (var i = 0; i < this.current_number-1; i++) {
this.animateTranslation(this.container.children[i],
this.padding,
this.duration/4)
}
The above code run correctly if we open and keep this current tab.
The problem is when we move to another tab, do something and then move back, some objects have the same position, that cause the translation to the same position. It looks weird.
It appears on both Chrome, Firefox and IE11.
I dont know why, please point me out what happened.
Most modern browsers choose to limit the delay in setInterval and pause requestAnimationFrame in inactive tabs. This is done in order to preserve CPU cycles and to reduce power consumption, especially important for mobile devices. You can find more details about each browser in this answer
That means, while the tab is inactive, your tween animation is not working the way it is normally expected to.
A simple solution would be to halt the main animation loop if the tab is inactive using a variable.
window.onfocus = function () {
isActive = true;
};
window.onblur = function () {
isActive = false;
};
How to access urls of images and xy coordinates from the DOM.
I have a div with multiple image gifs in it.
The gifs represent electronic components on stripboard or protoboard.
The img gifs are generated using this code.
function createDiv(img)//img here original code was for creating new divs
{
alert(divnumber);//an incrementing or decrementing image array position counter
{
var divTag = document.createElement("img");
divTag.id ='part'+divnumber;
imageArray[divnumber+1]=200;//arbitrary inital x placement
imageArray[divnumber+2]=200;//arbitrary initial y placment
divTag.className ="dragme";
divTag.src = imageArray[divnumber];//gif;//imageArray[i];
document.body.appendChild(divTag);
}
divnumber=divnumber+3;//offset between gif url in image array
}
The gifs are draggable using this code. I don't fully understand drag code but it was the simplest I could find and make work.
//<script language="JavaScript1.2">
<!--
var ie=document.all;//if using explorer
var nn6=document.getElementById&&!document.all;//if using netscape
var isdrag=false;//are we dragging??
var x,y;
var dobj;//drag object
function movemouse(e)
{
if (isdrag) //if drag istrue
{
dobj.style.left = nn6 ? tx + e.clientX - x : tx + event.clientX - x;
//alert(dobj.style.left);
dobj.style.top = nn6 ? ty + e.clientY - y : ty + event.clientY - y;
return false;
}
}
function selectmouse(e)
{
var fobj = nn6 ? e.target : event.srcElement;
var topelement = nn6 ? "HTML" : "BODY";
while (fobj.tagName != topelement && fobj.className != "dragme")
{
fobj = nn6 ? fobj.parentNode : fobj.parentElement;
}
if (fobj.className=="dragme")
{
isdrag = true;
dobj = fobj;
tx = parseInt(dobj.style.left+0);
//alert(tx);
ty = parseInt(dobj.style.top+0);
x = nn6 ? e.clientX : event.clientX;
//alert(x +' "=y);
y = nn6 ? e.clientY : event.clientY;
document.onmousemove=movemouse;
return false;
}
}
document.onmousedown=selectmouse;//go to selectmouse when mouse down in document
document.onmouseup=new Function("isdrag=false");
//-->
I need to put all the gifs and x y coordinates into an array that I can save with html5 local storage.
I can save an array and recall it ok.
But I need to fill the array with urls and xy coords of draggable items.
I can't figure how to get that info from either the dragging code or the DOM.
I think I can get that info from the dom image list but I still cant get up to speeds on all the dom details.
Can anyone tell me how to identify the gif url and xy coordinates from either the drag code or the DOM.
This is basically my last hurdle before I can comnplete the prrogram.
Many Thanks. I am mainly a cut and paste and hacking found scripts in my programming level.
Oh!! I am almost 70 and this IS NOT a homework problem!!
Thanks markE for last help.
TiMathis
After further thought I can probably dig the xy's out of the drag code but how can I determine which gif is being dragged?
OK I can get the objects id ...alert(dobj.id)
I should be able to use that to get other info for immage array info I need.
if (fobj.className=="dragme")
{
isdrag = true;
dobj = fobj;
alert(dobj.id);
tx = parseInt(dobj.style.left+0);
//alert(tx);
ty = parseInt(dobj.style.top+0);
x = nn6 ? e.clientX : event.clientX;
//alert(x +' "=y);
y = nn6 ? e.clientY : event.clientY;
document.onmousemove=movemouse;
return false;
}
}