I want to show two animation simultaneously programatically not in XML file.It should ROTATE and TRANSLATE
how can I do that?
Please suggest me some way??????
Here is ma code:>
ImageView snowImg1 = (ImageView) findViewById(R.id.snowimg1);
snowImg1.setVisibility(0);
ImageView snowImg2 = (ImageView) findViewById(R.id.snowimg2);
snowImg2.setVisibility(0);
ImageView snowImg3 = (ImageView) findViewById(R.id.snowimg3);
snowImg3.setVisibility(0);
ImageView snowImg4 = (ImageView) findViewById(R.id.snowimg4);
snowImg4.setVisibility(0);
ImageView snowImg6 = (ImageView) findViewById(R.id.snowimg6);
snowImg6.setVisibility(0);
ImageView snowImg5 = (ImageView) findViewById(R.id.snowimg5);
snowImg5.setVisibility(0);
View snowArray[] = {snowImg1, snowImg2, snowImg3, snowImg4, snowImg5, snowImg6};
Animation snowMov7 = new RotateAnimation(0,360, Animation.RELATIVE_TO_SELF,0.5f , Animation.RELATIVE_TO_SELF,0.5f );
snowMov7.setRepeatCount(Animation.INFINITE);
Animation snowMov1 = new TranslateAnimation(Animation.RELATIVE_TO_PARENT, 0.1f, Animation.RELATIVE_TO_PARENT, 0.3f, Animation.RELATIVE_TO_PARENT, 0.0f, Animation.RELATIVE_TO_PARENT, 0.9f);
snowMov1.setDuration(10000);
Animation snowMov2 = new TranslateAnimation(Animation.RELATIVE_TO_PARENT, 0.3f, Animation.RELATIVE_TO_PARENT, 0.4f, Animation.RELATIVE_TO_PARENT, -0.1f, Animation.RELATIVE_TO_PARENT, 0.9f);
snowMov2.setDuration(10100);
Animation snowMov3 = new TranslateAnimation(Animation.RELATIVE_TO_PARENT, 0.5f, Animation.RELATIVE_TO_PARENT, 0.1f, Animation.RELATIVE_TO_PARENT, -0.1f, Animation.RELATIVE_TO_PARENT, 0.9f);
snowMov3.setDuration(10200);
Animation snowMov4 = new TranslateAnimation(Animation.RELATIVE_TO_PARENT, 0.7f, Animation.RELATIVE_TO_PARENT, 0.2f, Animation.RELATIVE_TO_PARENT,-0.1f, Animation.RELATIVE_TO_PARENT, 0.9f);
snowMov4.setDuration(10300);
Animation snowMov5 = new TranslateAnimation(Animation.RELATIVE_TO_PARENT, 0.6f, Animation.RELATIVE_TO_PARENT, 0.7f, Animation.RELATIVE_TO_PARENT, 0.0f, Animation.RELATIVE_TO_PARENT, 0.9f);
snowMov5.setDuration(10400);
Animation snowMov6 = new TranslateAnimation(Animation.RELATIVE_TO_PARENT, 0.9f, Animation.RELATIVE_TO_PARENT, 0.9f, Animation.RELATIVE_TO_PARENT, 0.05f, Animation.RELATIVE_TO_PARENT, 0.9f);
snowMov6.setDuration(10500);
Animation movArray[] = {snowMov1,snowMov2, snowMov3, snowMov4, snowMov5, snowMov6,snowMov7};
for(int i=0;i<6;i++)
{
movArray[i].reset();
movArray[i].setFillAfter(true);
movArray[i].setAnimationListener(this);
snowArray[i].startAnimation(movArray[i]);
snowArray[i].startAnimation(movArray[6]);
}
Can we use startAnimation twice in program???Please help me?
I have done it Using ANIMATIONSET we can do this.
AnimationSet snowMov1 = new AnimationSet(true);
RotateAnimation rotate1 = new RotateAnimation(0,360, Animation.RELATIVE_TO_SELF,0.5f , Animation.RELATIVE_TO_SELF,0.5f );
rotate1.setStartOffset(50);
rotate1.setDuration(9500);
snowMov1.addAnimation(rotate1);
TranslateAnimation trans1 = new TranslateAnimation(Animation.RELATIVE_TO_PARENT, 0.1f, Animation.RELATIVE_TO_PARENT, 0.3f, Animation.RELATIVE_TO_PARENT, 0.0f, Animation.RELATIVE_TO_PARENT, 0.9f);
trans1.setDuration(12000);
snowMov1.addAnimation(trans1);
In this way we can made set for multiple animations.
Related
I am trying to make my 3d object to move. Using default vs2022 template I managed to import model from .ply file and load to pixelshader / vertexshader. Object is displaying on screen, but I have no idea how could I move it. I know I can edit all verticies but I think there is other way of doing it using Matrix.
I was trying to do
XMStoreFloat4x4(&m_constantBufferData.model, XMMatrixTranslation(0.5f, 0.0f, 0.0f));
But It shreded textures.
Upper image is after move.
Can someone help me and explain how to do this?
Camera Initialize:
void Sample3DSceneRenderer::CreateWindowSizeDependentResources()
{
Size outputSize = m_deviceResources->GetOutputSize();
float aspectRatio = outputSize.Width / outputSize.Height;
float fovAngleY = 70.0f * XM_PI / 180.0f;
if (aspectRatio < 1.0f)
{
fovAngleY *= 2.0f;
}
XMMATRIX perspectiveMatrix = XMMatrixPerspectiveFovRH(
fovAngleY,
aspectRatio,
0.01f,
100.0f
);
XMFLOAT4X4 orientation = m_deviceResources->GetOrientationTransform3D();
XMMATRIX orientationMatrix = XMLoadFloat4x4(&orientation);
XMStoreFloat4x4(
&m_constantBufferData.projection,
XMMatrixTranspose(perspectiveMatrix * orientationMatrix)
);
static const XMVECTORF32 eye = { 0.0f, 0.7f, 8.0f, 0.0f };
static const XMVECTORF32 at = { 0.0f, -0.1f, 0.0f, 0.0f };
static const XMVECTORF32 up = { 0.0f, 1.0f, 0.0f, 0.0f };
XMStoreFloat4x4(&m_constantBufferData.view, XMMatrixTranspose(XMMatrixLookAtRH(eye, at, up)));
}
void Sample3DSceneRenderer::Move()
{
XMStoreFloat4x4(&m_constantBufferData.model, XMMatrixTranslation(0.5f, 0.0f, 0.0f));
}
To demonstrate my problem I use libgdx's ShadowMappingTest.
This test has model with box and sphere:
ModelBuilder modelBuilder = new ModelBuilder();
modelBuilder.begin();
MeshPartBuilder mpb = modelBuilder.part("parts", GL20.GL_TRIANGLES, Usage.Position | Usage.Normal | Usage.ColorUnpacked,
new Material(ColorAttribute.createDiffuse(Color.WHITE)));
mpb.setColor(1f, 1f, 1f, 1f);
mpb.box(0, -1.5f, 0, 10, 1, 10);
mpb.setColor(1f, 0f, 1f, 1f);
mpb.sphere(2f, 2f, 2f, 10, 10);
model = modelBuilder.end();
instance = new ModelInstance(model);
And on screen:
Then I replaced sphere by triangle:
val modelBuilder = ModelBuilder()
modelBuilder.begin()
val mpb = modelBuilder.part("parts",
GL20.GL_TRIANGLES,
(Usage.Position or Usage.Normal or Usage.ColorUnpacked).toLong(),
Material(ColorAttribute.createDiffuse(Color.WHITE)))
mpb.setColor(1f, 1f, 1f, 1f)
mpb.box(0f, -1.5f, 0f, 10f, 1f, 10f)
mpb.setColor(1f, 0f, 1f, 1f)
mpb.triangle(Vector3(0f, 2f, 3f), <<<<<< look
Vector3(3f, 2f, 0f),
Vector3(0f, 2f, 0f))
model = modelBuilder.end()
instance = ModelInstance(model)
And I got:
Where is shadow of the triangle?
How can I fix it?
I am trying to show an Activity Indicator in my App for which I have written the following code but the indicator is not getting rendered on the screen.
Can somebody please suggest what has gone wrong?
private ActivityIndicator indicator = new ActivityIndicator
{
HorizontalOptions = LayoutOptions.CenterAndExpand,
Color = Color.Black,
IsVisible = false
};
StackLayout stack = new StackLayout
{
VerticalOptions=LayoutOptions.FillAndExpand,
HorizontalOptions=LayoutOptions.FillAndExpand,
Padding=0,
Spacing=0,
};
AbsoluteLayout absolute = new AbsoluteLayout
{
VerticalOptions = LayoutOptions.FillAndExpand,
HorizontalOptions = LayoutOptions.FillAndExpand,
};
stack.Children.Add(map);
stack.Children.Add(browser);
AbsoluteLayout.SetLayoutFlags(stack, AbsoluteLayoutFlags.PositionProportional);
AbsoluteLayout.SetLayoutBounds(stack, new Rectangle(0f, 0f, AbsoluteLayout.AutoSize, AbsoluteLayout.AutoSize));
AbsoluteLayout.SetLayoutFlags(indicator, AbsoluteLayoutFlags.PositionProportional);
AbsoluteLayout.SetLayoutBounds(indicator, new Rectangle(0.5f, 0.5f, AbsoluteLayout.AutoSize, AbsoluteLayout.AutoSize));
absolute.Children.Add(indicator);
absolute.Children.Add(stack);
*//When Some activity occurs.....Indicator is shown like this*
indicator.SetBinding(ActivityIndicator.IsVisibleProperty, "IsBusy", BindingMode.OneWay);
indicator.SetBinding(ActivityIndicator.IsRunningProperty, "IsBusy", BindingMode.OneWay);
indicator.IsRunning = true;
indicator.IsVisible = true;
Try this
AbsoluteLayout.SetLayoutBounds(stack, new Rectangle(0f, 0f, 1f, 1f));
AbsoluteLayout.SetLayoutBounds(indicator, new Rectangle(0.5f, 0.5f, -1f, -1f));
AbsoluteLayout.SetLayoutFlags(stack, AbsoluteLayoutFlags.All);
Add the indicator after the stack. absolute.Children.Add(indicator) after absolute.Children.Add(stack);
Check If your IsVisible is true.
My code for view 3D object Card is View as like this image. Please check this URL:
https://lh3.googleusercontent.com/zKVd6Pnv0xzRcG5QdVpGSFnWbYDqyrC4vyF2n264NDE=w359-h207-p-no
https://lh5.googleusercontent.com/ZAsvunwH18MpfGcYSCH7RY0DXhNZgZBrDXLLZIfw_U8=w316-h207-p-no
Vector3 cameraPosition = new Vector3(0.0f, 15.0f, -5.0f);
float aspectRatio = graphics.GraphicsDevice.Viewport.AspectRatio;
foreach (ModelMesh mesh in myModel.Meshes)
{
foreach (BasicEffect effect in mesh.Effects)
{
effect.World = Matrix.Identity;
effect.View = Matrix.CreateLookAt(cameraPosition,Vector3.Zero, Vector3.Up);
effect.Projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.PiOver4, aspectRatio,
1.0f, 8000.0f);
}
mesh.Draw();
}
Please help me on this.
I made my borders with this:
class Maze
{
private Body _agentBody;
private Sprite _box;
private GameplayScreen _screen;
private float _offset;
public Maze(World world, GameplayScreen screen, Vector2 position)
{
_agentBody = BodyFactory.CreateBody(world, position);
_agentBody.BodyType = BodyType.Dynamic;
_agentBody.IsStatic = true;
_agentBody.Restitution = 0.2f;
_agentBody.Friction = 0.2f;
_offset = ConvertUnits.ToDisplayUnits(1f);
// spodek
_agentBody.CreateFixture(new PolygonShape(PolygonTools.CreateRectangle(1f, 0.05f, new Vector2(0f, 1f), 0), 1f));
// spodek
_agentBody.CreateFixture(new PolygonShape(PolygonTools.CreateRectangle(1f, 0.05f, new Vector2(0f, -1f), 0), 1f));
// pravy bok
_agentBody.CreateFixture(new PolygonShape(PolygonTools.CreateRectangle(0.05f, 1f, new Vector2(1f, 0f), 0), 1f));
// levy bok
_agentBody.CreateFixture(new PolygonShape(PolygonTools.CreateRectangle(0.05f, 1f, new Vector2(-1f, 0f), 0), 1f));
_screen = screen;
//GFX
AssetCreator creator = _screen.ScreenManager.Assets;
_box = new Sprite(creator.TextureFromVertices(PolygonTools.CreateRectangle(1f, 0.05f),
MaterialType.Blank, Color.White, 1f));
}
public Body Body
{
get { return _agentBody; }
}
public void Draw()
{
SpriteBatch batch = _screen.ScreenManager.SpriteBatch;
batch.Draw(_box.Texture, ConvertUnits.ToDisplayUnits(_agentBody.Position), null,
Color.White, _agentBody.Rotation, _box.Origin + new Vector2(0f, _offset), 1f, SpriteEffects.None, 0f);
batch.Draw(_box.Texture, ConvertUnits.ToDisplayUnits(_agentBody.Position), null,
Color.White, _agentBody.Rotation, _box.Origin + new Vector2(0f, -_offset), 1f, SpriteEffects.None, 0f);
batch.Draw(_box.Texture, ConvertUnits.ToDisplayUnits(_agentBody.Position), null,
Color.White, _agentBody.Rotation + MathHelper.Pi / 2f, _box.Origin + new Vector2(0f, _offset), 1f, SpriteEffects.None, 0f);
batch.Draw(_box.Texture, ConvertUnits.ToDisplayUnits(_agentBody.Position), null,
Color.White, _agentBody.Rotation + MathHelper.Pi / 2f, _box.Origin + new Vector2(0f, -_offset), 1f, SpriteEffects.None, 0f);
}
}
And these are my little particles:
for (int i = 0; i < 8; i++)
{
_sands[i] = BodyFactory.CreateRectangle(_world, 0.05f, 0.05f, 1f);
_sands[i].IsStatic = false;
_sands[i].Restitution = 0.1f;
_sands[i].Friction = 0.1f;
_sands[i].Position = new Vector2(1.8f + i * 0.2f, 2.2f);
}
_sand = new Sprite(ScreenManager.Assets.TextureFromShape(_sands[0].FixtureList[0].Shape,
MaterialType.Dots,
Color.SandyBrown, 0.8f));
I draw it this way:
foreach (Body sand in _sands)
{
spriteBatch.Draw(_sand.Texture, ConvertUnits.ToDisplayUnits(sand.Position), null, Color.SandyBrown, sand.Rotation, _sand.Origin, 1f, SpriteEffects.None, 0f);
}
_maze.Draw();
But I can't figure out why if I rotate with borders then why partlicles are still in place. I tried change restitution of particles and when there is 1f they are restitute (bouncing) allright and I can rotate with borders and they restitute from new position of borders but when I have settings like above particles fall down, the ones which are inside of borders they stopped at bottom border and others fall down entirely. So after start I have first image and after I rotate with borders I get seccond image. What I am doing wrong? Why when I change restitution they are bouncing a with 0.2 they are not?
Edit:
New lines in maze constructor:
agentBody = BodyFactory.CreateBody(world, position);
_agentBody.BodyType = BodyType.Dynamic;
_agentBody.IgnoreGravity = true;
_agentBody.Restitution = 0.1f;
_agentBody.Friction = 1f;
_offset = ConvertUnits.ToDisplayUnits(1.5f);
FixtureFactory.AttachRectangle(3f, 0.1f, 1f, new Vector2(0, 1.55f), _agentBody);
FixtureFactory.AttachRectangle(3f, 0.1f, 1f, new Vector2(0f, -1.55f), _agentBody);
FixtureFactory.AttachRectangle(width, 3f, 1f, new Vector2(-1.55f, 0f), _agentBody);
FixtureFactory.AttachRectangle(width, 3f, 1f, new Vector2(1.55f, 0f), _agentBody);
This is how it looks with debug view:
Rotating with body:
public override void HandleInput(GameTime gameTime, InputState input)
{
if (input == null)
throw new ArgumentNullException("input");
// Read in our gestures
foreach (GestureSample gesture in input.Gestures)
{
if (gesture.GestureType == GestureType.HorizontalDrag)
{
if (gesture.Delta.X < 0)
{
_maze.Body.Rotation += 0.02f;
}
else if (gesture.Delta.X > 0)
{
_maze.Body.Rotation -= 0.02f;
}
}
}
The little particle bodies are probably sleeping once they stop moving. The frame around them is a static body so the engine does not expect it to ever move, but you are moving it. In this situation the little particle bodies will not wake up.
You will need to set the little particle bodies so that they cannot sleep, or make the frame around them a dynamic or kinematic body. As a general rule, if a body is gonna move, don't make it a static body.