RotateAnimation with translationX translationY change in axml - animation

I would like to rotate an image.
new RotateAnimation(0, 360, Dimension.RelativeToSelf, 0.5f, Dimension.RelativeToSelf, 0.5f)
{
Duration = 1000,
FillAfter = false,
RepeatCount = 1,
RepeatMode = RepeatMode.Restart
};
It works perfetly when I don't have set tranlationX and Y in my axml
<ImageView
android:id="#+id/Icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:translationX="15dp"
android:translationY="-30dp" />
What do I miss?

Related

Unable to use Pointer Lock with PerspectiveCamera and PointerLockControls

I like react-three and I am trying to make an FPV character with a body:
https://codesandbox.io/s/fpv-player-ers63
So the goal is that the camera is placed at the head level and the character moves around like in original example https://codesandbox.io/s/minecraft-vkgi6 by Paul Henschel
drcmda
I have added PerspectiveCamera to change the camera position but now PointerLockControls doesn't work any more and I do not understand why and how to handle it.
Thank you
PerspectiveCamera usage
export const Player = (props) => {
const axe = useRef()
const [ref, api] = useSphere(() => ({ mass: 1, type: "Dynamic", position: [0, 10, 0], ...props }))
const { forward, backward, left, right, jump } = usePlayerControls()
const { camera } = useThree()
const velocity = useRef([0, 0, 0])
useEffect(() => api.velocity.subscribe((v) => (velocity.current = v)), [])
useFrame((state) => {
ref.current.getWorldPosition(camera.position)
frontVector.set(0, 0, Number(backward) - Number(forward))
sideVector.set(Number(left) - Number(right), 0, 0)
direction.subVectors(frontVector, sideVector).normalize().multiplyScalar(SPEED).applyEuler(camera.rotation)
speed.fromArray(velocity.current)
axe.current.children[0].rotation.x = THREE.MathUtils.lerp(
axe.current.children[0].rotation.x,
Math.sin((speed.length() > 1) * state.clock.elapsedTime * 10) / 20,
0.01,
)
axe.current.rotation.copy(camera.rotation)
axe.current.position.copy(camera.position).add(camera.getWorldDirection(rotation).multiplyScalar(1))
api.velocity.set(direction.x, velocity.current[1], direction.z)
if (jump && Math.abs(velocity.current[1].toFixed(2)) < 0.05) api.velocity.set(velocity.current[0], 10, velocity.current[2])
})
return (
<>
<mesh ref={ref} />
<group ref={axe} onPointerMissed={(e) => (axe.current.children[0].rotation.x = -0.5)}>
<group position={[0, 7, 0]}>
<PerspectiveCamera makeDefault={true} fov={75}>
<Body position={[0, -4, 1]} />
</PerspectiveCamera>
</group>
</group>
</>
)
}
PointerLockControls usage
export default function App() {
return (
<Canvas
shadows
gl={{ alpha: false }}
camera={{ fov: 45 }}
raycaster={{
computeOffsets: (e) => ({ offsetX: e.target.width / 2, offsetY: e.target.height / 2 }),
}}>
<Sky sunPosition={[100, 20, 100]} />
<ambientLight intensity={0.3} />
<pointLight castShadow intensity={0.8} position={[100, 100, 100]} />
<Physics gravity={[0, -30, 0]}>
<Ground />
<Player />
<Reflector
blur={[0, 0]} // Blur ground reflections (width, heigt), 0 skips blur
mixBlur={0.1} // How much blur mixes with surface roughness
mixStrength={0.25} // Strength of the reflections
resolution={1024} // Off-buffer resolution, lower=faster, higher=better quality
args={[10, 30]} // PlaneBufferGeometry arguments
position={[0, 0, -20]}
rotation={[0, 0, 2 * Math.PI]}
mirror={0.5} // Mirror environment, 0 = texture colors, 1 = pick up env colors
minDepthThreshold={0.25}
maxDepthThreshold={1}
depthScale={50}>
{(Material, props) => <Material metalness={0} roughness={0} {...props} />}
</Reflector>
</Physics>
<PointerLockControls />
</Canvas>
)
}
Browser: Firefox 94.0.2 (64-bit), macOS Monterey
"dependencies": {
"#pmndrs/branding": "0.0.8",
"#react-three/cannon": "4.0.1",
"#react-three/drei": "7.17.2",
"#react-three/fiber": "7.0.17",
"#types/three": "0.133.1",
"react": "17.0.2",
"react-dom": "17.0.2",
"react-scripts": "4.0.3",
"simplex-noise": "3.0.0",
"three": "0.133.1",
"zustand": "3.6.1"
},
https://codesandbox.io/s/fpv-player-ers63
Well, I found that it is sufficient to offset the camera in useFrame update
https://codesandbox.io/s/fpv-player-ers63
export const Player = (props) => {
const axe = useRef()
const [ref, api] = useSphere(() => ({ args: [1], mass: 1, type: "Dynamic", position: [0, 10, 0], ...props }))
const { forward, backward, left, right, jump } = usePlayerControls()
const { camera } = useThree()
const velocity = useRef([0, 0, 0])
useEffect(() => api.velocity.subscribe((v) => (velocity.current = v)), [])
useFrame((state) => {
ref.current.getWorldPosition(camera.position)
frontVector.set(0, 0, Number(backward) - Number(forward))
sideVector.set(Number(left) - Number(right), 0, 0)
direction.subVectors(frontVector, sideVector).normalize().multiplyScalar(SPEED).applyEuler(camera.rotation)
speed.fromArray(velocity.current)
axe.current.children[0].rotation.x = THREE.MathUtils.lerp(
axe.current.children[0].rotation.x,
Math.sin((speed.length() > 1) * state.clock.elapsedTime * 10) / 10,
0.1,
)
axe.current.rotation.copy(camera.rotation)
axe.current.position.copy(camera.position).add(camera.getWorldDirection(rotation).multiplyScalar(1))
camera.position.setY(camera.position.y + 8)
api.velocity.set(direction.x, velocity.current[1], direction.z)
if (jump && Math.abs(velocity.current[1].toFixed(2)) < 0.05) api.velocity.set(velocity.current[0], 10, velocity.current[2])
})
return (
<>
<mesh ref={ref} />
<group ref={axe} onPointerMissed={(e) => (axe.current.children[0].rotation.x = -0.5)}>
<Body position={[0, 4, 0]} />
</group>
</>
)
}

Objects don't overlap when rotating

I'm trying to reproduce this animation (see below) with react-three-fiber. I'm still very new to this package and to three-js.
http://makesportmakebook.com/livres/.
I've been able to do create book shapes with meshLambertMaterial, as such:
function Book(props) {
const mesh = useRef();
useFrame(() => {
mesh.current.rotation.x = mesh.current.rotation.y += 0.01
})
const bookCover = useLoader(TextureLoader, bookCoverImg)
const bookSpine = useLoader(TextureLoader, bookSpineImg)
const bookBack = useLoader(TextureLoader, bookBackImg)
const bookPages = useLoader(TextureLoader, bookPagesImg)
const bookPagesTexture = useLoader(TextureLoader, bookPagesTextureImg)
const bookPagesTopBottomTexture = useLoader(TextureLoader, bookPagesTopBottomTextureImg)
return (
<mesh
position={props.position}
ref={mesh}>
<boxBufferGeometry attach="geometry" args={
[
7, 10, 1.2, 4, 4, 1
]
} />
<meshLambertMaterial color={"0xffffff"} map={bookCover} />
<meshLambertMaterial map={bookSpine} />
<meshLambertMaterial map={bookBack} />
<meshLambertMaterial map={bookPages} />
<meshLambertMaterial map={texture_5} />
<meshLambertMaterial map={texture_6} />
</mesh>
)
};
Here's a code sandbox of my code so far: https://codesandbox.io/s/cocky-fast-61ndj
My question is: how can I avoid the overlap of these you can see here (below) but still keep the same parallel position we can see in the first example?
There are two ways that you could handle this. The first is to move the camera instead of the books. The second is that instead of moving the books separately, move them as a group. I suspect that this second method is what you want to do.
This was quick and dirty, but it works.
Create a function to house the two books. Put the two books in a group and rotate the group.
import React, { useRef, Suspense } from "react";
import { Canvas, useFrame, extend, useLoader } from "react-three-fiber";
import { OrbitControls, StandardEffects, draco } from "drei";
import { TextureLoader } from "three/src/loaders/TextureLoader.js";
extend({ OrbitControls });
function Bookshelf(props) {
const mesh = useRef();
useFrame(() => {
mesh.current.rotation.x = mesh.current.rotation.y += 0.01;
});
return (
<group ref={mesh} position={[0, 0, 0]}>
<Suspense fallback={null}><Book position={[3, 0, 3]} /></Suspense>
<Suspense fallback={null}><Book position={[-3, 0, 0]} /></Suspense>
</group>
)
}
function Book(props) {
const bookCover = useLoader(
TextureLoader,
"https://res.cloudinary.com/www-c-t-l-k-com/image/upload/v1607732427/HEAD_PUBLISHING/book-cover.jpg"
);
const bookSpine = useLoader(
TextureLoader,
"https://res.cloudinary.com/www-c-t-l-k-com/image/upload/v1607732420/HEAD_PUBLISHING/book-back.jpg"
);
const bookBack = useLoader(
TextureLoader,
"https://res.cloudinary.com/www-c-t-l-k-com/image/upload/v1607732421/HEAD_PUBLISHING/book-side.jpg"
);
const bookPages = useLoader(
TextureLoader,
"https://res.cloudinary.com/www-c-t-l-k-com/image/upload/v1607732421/HEAD_PUBLISHING/book-side.jpg"
);
const texture_5 = useLoader(
TextureLoader,
"https://res.cloudinary.com/www-c-t-l-k-com/image/upload/v1607732427/HEAD_PUBLISHING/book-cover.jpg"
);
const texture_6 = useLoader(
TextureLoader,
"https://res.cloudinary.com/www-c-t-l-k-com/image/upload/v1607732421/HEAD_PUBLISHING/book-spine.jpg"
);
return (
<mesh position={props.position} >
<boxBufferGeometry attach="geometry" args={[7, 10, 1.2, 4, 4, 1]} />
<meshLambertMaterial color={"0xffffff"} map={bookCover} />
<meshLambertMaterial map={bookSpine} />
<meshLambertMaterial map={bookBack} />
<meshLambertMaterial map={bookPages} />
<meshLambertMaterial map={texture_5} />
<meshLambertMaterial map={texture_6} />
</mesh>
);
}
export default function App() {
let styling = {
width: "100vw",
height: "100vh",
position: "relative"
};
return (
<div style={{ position: "relative" }}>
<Canvas camera={{ position: [0, 0, 20] }} style={styling}>
<ambientLight intensity={0.3} />
<directionalLight intensity={1} />
<Suspense fallback={null}>
<Bookshelf>
</Bookshelf>
</Suspense>
<OrbitControls enableZoom={false} />
</Canvas>
</div>
);
}

In Xamarin, is there any way to use the MaxY Property in xaml during the use of a RelativeLayout?

I want to do this:
RelativeLayout.YConstraint="{ ConstraintExpression
Type=RelativeToView,
ElementName=info_box,
Property=Y+Height,
Factor=1,
Constant=22
}
Is there any way of achieving this in xaml or am I too attached to xaml and should not worry about it and do things like this in code?
I'm afraid you have to do it in code behind and here is an example I tried:
public MainPage()
{
InitializeComponent();
RelativeLayout layout = new RelativeLayout();
BoxView redBox = new BoxView() {BackgroundColor = Color.Red };
BoxView blueBox = new BoxView() { BackgroundColor = Color.Blue };
layout.Children.Add(redBox, Constraint.RelativeToParent((parent) => {
return parent.X;
}), Constraint.RelativeToParent((parent) => {
return parent.Y * .15;
}), Constraint.RelativeToParent((parent) => {
return parent.Width;
}), Constraint.RelativeToParent((parent) => {
return parent.Height * .8;
}));
layout.Children.Add(blueBox, Constraint.RelativeToView(redBox, (Parent, sibling) => {
return sibling.X + 20;
}), Constraint.RelativeToView(redBox, (parent, sibling) => {
return sibling.Y + redBox.Height;
}), Constraint.RelativeToParent((parent) => {
return parent.Width * .5;
}), Constraint.RelativeToParent((parent) => {
return parent.Height * .5;
}));
Content = layout;
}
Or define the controls in the xaml and change the YConstraint in code behind:
RelativeLayout.SetYConstraint(blueBox, Constraint.RelativeToView(redBox, (parent, sibling) =>
{
return sibling.Y + sibling.Height;
}));
In xaml:
<RelativeLayout>
<BoxView Color="Red" x:Name="redBox"
RelativeLayout.YConstraint="{ConstraintExpression Type=RelativeToParent,
Property=Height,Factor=.15,Constant=0}"
RelativeLayout.WidthConstraint="{ConstraintExpression
Type=RelativeToParent,Property=Width,Factor=1,Constant=0}"
RelativeLayout.HeightConstraint="{ConstraintExpression
Type=RelativeToParent,Property=Height,Factor=.4,Constant=0}" />
<BoxView Color="Blue" x:Name="blueBox"
RelativeLayout.YConstraint="{ ConstraintExpression Type=RelativeToView,ElementName=redBox,Property=Y,Factor= 1, Constant= 0}"
RelativeLayout.XConstraint="{ConstraintExpression Type=RelativeToView,
ElementName=redBox,Property=X,Factor=1,Constant=20}"
RelativeLayout.WidthConstraint="{ConstraintExpression
Type=RelativeToParent,Property=Width,Factor=.5,Constant=0}"
RelativeLayout.HeightConstraint="{ConstraintExpression
Type=RelativeToParent,Property=Height,Factor=.5,Constant=0}" />
</RelativeLayout>
BTW, you can easily achieve this layout by using a Grid (with single column) or Vertical StackLayout.

Highcharts Animation

Is there anyway to animate each and every bubble in bubble charts one by one, from left to right and the size of the bubbles will initially be either smaller or larger and then it should grow to the actual size. Any ideas to proceed further with this requirement is highly appreciated.
/**
* A Highcharts plugin to display the tooltip in a separate container outside the chart's
* bounding box, so that it can utilize all space available in the page.
*/
(function(H) {
H.wrap(H.Tooltip.prototype, 'getLabel', function(proceed) {
var chart = this.chart,
options = this.options,
chartRenderer = chart.renderer,
box;
if (!this.label) {
this.renderer = new H.Renderer(document.body, 400, 500);
box = this.renderer.boxWrapper;
box.css({
position: 'absolute',
top: '-9999px'
});
chart.renderer = this.renderer;
proceed.call(this, chart, options);
chart.renderer = chartRenderer;
this.label.attr({
x: 0,
y: 0
});
this.label.xSetter = function(value) {
box.element.style.left = value + 'px';
};
this.label.ySetter = function(value) {
box.element.style.top = value + 'px';
};
}
return this.label;
});
H.wrap(H.Tooltip.prototype, 'getPosition', function(proceed, boxWidth, boxHeight, point) {
var chart = this.chart,
chartWidth = chart.chartWidth,
chartHeight = chart.chartHeight,
pos;
point.plotX += this.chart.pointer.chartPosition.left;
point.plotY += this.chart.pointer.chartPosition.top;
// Temporary set the chart size to the full document, so that the tooltip positioner picks it up
chart.chartWidth = $(document).width();
chart.chartHeight = $(document).height();
// Compute the tooltip position
pos = proceed.call(this, boxWidth, boxHeight, point);
// Reset chart size
chart.chartWidth = chartWidth;
chart.chartHeight = chartHeight;
return pos;
});
/**
* Find the new position and perform the move. This override is identical
* to the core function, except the anchorX and anchorY arguments to move().
*/
H.Tooltip.prototype.updatePosition = function(point) {
var chart = this.chart,
label = this.label,
pos = (this.options.positioner || this.getPosition).call(
this,
label.width,
label.height,
point
);
// do the move
this.move(
Math.round(pos.x),
Math.round(pos.y || 0), // can be undefined (#3977)
point.plotX + chart.plotLeft - pos.x,
point.plotY + chart.plotTop - pos.y
);
};
}(Highcharts));
var chart = new Highcharts.Chart({
chart: {
height: 500,
renderTo: 'container',
type: 'pie'
},
tooltip: {
formatter: function() {
return '<div class="MyChartTooltip">test<br /> test<br /> test<br /> test<br /> test<br /> test<br /> test<br /> test<br /> test<br /> test<br /> test<br /> test<br /> test<br /> test<br /> test<br /> test<br /> test<br /> test<br /> test<br /> test<br /> test<br /> test<br /> test<br /> test<br /> test<br /> test<br /> test<br /> test<br /> test<br /> </div>';
}
},
series: [{
data: [29.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4]
}]
});
You can add point with small z values and then update them one by one asynchronously (after the one point is updated, update the next one)
You can also override bubble.prototype.animate function and change default animation-like this:
Highcharts.seriesTypes.bubble.prototype.animate = function(init) {
var H = Highcharts
var each = H.each
var animation = this.options.animation;
var points = this.points
var animatePoint = i => {
var point = points[i]
var graphic = point && point.graphic
var animationTarget
if (graphic && graphic.width) {
animationTarget = {
x: graphic.targetX,
y: graphic.targetY,
width: graphic.targetWidth,
height: graphic.targetHeight
}
graphic.animate(animationTarget, animation, () => {
animatePoint(i + 1)
});
} else {
this.update({ dataLabels: { enabled: true }})
}
}
if (!init) { // run the animation
each(points, function(point) {
var graphic = point.graphic,
animationTarget;
if (graphic && graphic.width) { // URL symbols don't have width
graphic.targetWidth = graphic.width
graphic.targetHeight = graphic.height
graphic.targetX = graphic.x
graphic.targetY = graphic.y
// Start values
graphic.attr({
x: point.plotX,
y: point.plotY,
width: 1,
height: 1
});
}
});
animatePoint(0)
// delete this function to allow it only once
this.animate = null;
}
}
example: http://jsfiddle.net/hpk497hb/

Scrollable View not displaying properly in appcelerator

I ahve implemented a scrollable view in appcelerator. but only the first and the last image is being displayed . the intermediate images are not loading. Any suggestions why ?
This is the code for the .xml file of the scrollable view.
<Alloy>
<View class="container">
<View class = " HeadingClass" >
<Label class="headingClass" top = "0%">Scrollable View And Animation Screen</Label>
</View>
<ScrollableView class = "scrollableViewClass" id="scrollableView">
<ImageView class="imgView1" id="imgViewId1"></ImageView>
<ImageView class="imgView2" id="imgViewId2"></ImageView>
<ImageView class="imgView3" id="imgViewId3"></ImageView>
<ImageView class="imgView4" id="imgViewId4"></ImageView>
<ImageView class="imgView5" id="imgViewId5"></ImageView>
</ScrollableView>
<!-- <View class="imageAnimationView" id="imageAnimation">
<ImageView class="animateImageClass" id="animateImage"></ImageView>
</View> -->
</View>
</Alloy> <Alloy>
<View class="container">
<View class = " HeadingClass" >
<Label class="headingClass" top = "0%">Scrollable View And Animation Screen</Label>
</View>
<ScrollableView class = "scrollableViewClass" id="scrollableView">
<ImageView class="imgView1" id="imgViewId1"></ImageView>
<ImageView class="imgView2" id="imgViewId2"></ImageView>
<ImageView class="imgView3" id="imgViewId3"></ImageView>
<ImageView class="imgView4" id="imgViewId4"></ImageView>
<ImageView class="imgView5" id="imgViewId5"></ImageView>
</ScrollableView>
<!-- <View class="imageAnimationView" id="imageAnimation">
<ImageView class="animateImageClass" id="animateImage"></ImageView>
</View> -->
</View>
</Alloy>
This is the code for .tss file
".container" : {
backgroundColor : "lightgray"
},
".headingClass" : {
height : "5%",
width : "70%",
font: {
fontFamily: 'Arial',
fontSize: '14%',
fontWeight: 'bold'
},
textAlign: Ti.UI.TEXT_ALIGNMENT_CENTER,
},
".HeadingClass" : {
backgroundColor : "gray",
top : "5%",
height : "6%",
width : "100%"
},
".scrollableViewClass" : {
top : "15%",
height : "30%",
width : "100%",
contentHeight: Ti.UI.SIZE,
contentWidth: Ti.UI.SIZE,
showPagingControl : true
},
".imgView1" : {
image : "/Images/appceleratorImage1.png",
height : "100%",
width : "100%"
},
".imgView2" : {
image : "/Images/appceleratorImage2.png",
height : "100%",
width : "100%"
},
".imgView3" : {
image : "/Images/appceleratorImage3.png",
height : "100%",
width : "100%"
},
".imgView4" : {
image : "/Images/appceleratorImage4.png",
height : "100%",
width : "100%"
},
".imgView5" : {
image : "/Images/appceleratorImage5.png",
height : "100%",
width : "100%"
}
Try putting <View>'s around the <ImageView>'s.
For testing purposes you could give them a backgroundColor to see if the pages are visible.

Resources