public bool OnTesselation(ITerrainMeshPool mesher, ITesselatorAPI tessThreadTesselator) { ICoreClientAPI capi = api as ICoreClientAPI; Matrixf mat = new Matrixf(); mat.RotateYDeg(block.Shape.rotateY); for (int i = 0; i < 8; i++) { if (inv[i].Empty) { continue; } ItemStack stack = inv[i].Itemstack; BlockCrock crockblock = stack.Collectible as BlockCrock; Vec3f rot = new Vec3f(0, block.Shape.rotateY, 0); MeshData mesh = BlockEntityCrock.GetMesh(tessThreadTesselator, api, crockblock, crockblock.GetContents(api.World, stack), crockblock.GetRecipeCode(api.World, stack), rot); float y = i >= 4 ? 10 / 16f : 2 / 16f; float x = (i % 2 == 0) ? 4 / 16f : 12 / 16f; float z = ((i % 4) >= 2) ? 10 / 16f : 4 / 16f; Vec4f offset = mat.TransformVector(new Vec4f(x - 0.5f, y, z - 0.5f, 0)); mesh.Translate(offset.XYZ); mesher.AddMeshData(mesh); } return(false); }
public override void Initialize(ICoreAPI api, JsonObject properties) { base.Initialize(api, properties); bepu = Blockentity as BEPulverizer; Matrixf mat = bepu.mat; leftOffset = mat.TransformVector(new Vec4f(4.5f / 16f - 0.5f, 4 / 16f, -4.5f / 16f, 0f)); rightOffset = mat.TransformVector(new Vec4f(11.5f / 16f - 0.5f, 4 / 16f, -4.5f / 16f, 0f)); slideDustParticles = new SimpleParticleProperties(1, 3, ColorUtil.ToRgba(40, 220, 220, 220), new Vec3d(), new Vec3d(), new Vec3f(-0.25f, -0.25f, -0.25f), new Vec3f(0.25f, 0.25f, 0.25f), 1, 1, 0.1f, 0.2f, EnumParticleModel.Quad); slideDustParticles.AddPos.Set(2 / 32f, 1 / 32f, 2 / 32f); slideDustParticles.WithTerrainCollision = false; slideDustParticles.ParticleModel = EnumParticleModel.Quad; slideDustParticles.LifeLength = 0.75f; slideDustParticles.SelfPropelled = true; slideDustParticles.GravityEffect = 0f; slideDustParticles.SizeEvolve = EvolvingNatFloat.create(EnumTransformFunction.QUADRATIC, 0.4f); slideDustParticles.OpacityEvolve = EvolvingNatFloat.create(EnumTransformFunction.QUADRATIC, -16f); slideDustParticles.MinQuantity = 1; slideDustParticles.AddQuantity = 3; Vec4f vec = mat.TransformVector(new Vec4f(-0.1f, -0.1f, 0.2f, 0f)); slideDustParticles.MinVelocity.Set(vec.X, vec.Y, vec.Z); vec = mat.TransformVector(new Vec4f(0.2f, -0.05f, 0.2f, 0f)); slideDustParticles.AddVelocity.Set(vec.X, vec.Y, vec.Z); leftSlidePos = mat.TransformVector(new Vec4f(4.5f / 16f - 0.5f, 4 / 16f, -2.5f / 16f, 0f)).XYZ.ToVec3d().Add(Position).Add(0.5, 0, 0.5); rightSlidePos = mat.TransformVector(new Vec4f(11.5f / 16f - 0.5f, 4 / 16f, -2.5f / 16f, 0f)).XYZ.ToVec3d().Add(Position).Add(0.5, 0, 0.5); }
public override void Initialize(ICoreAPI api) { base.Initialize(api); ownBlock = Block as BlockCondenser; if (Api.Side == EnumAppSide.Client) { currentMesh = GenMesh(); MarkDirty(true); RegisterGameTickListener(clientTick, 200, Api.World.Rand.Next(50)); if (!inventory[1].Empty && bucketMesh == null) { genBucketMesh(); } } Matrixf mat = new Matrixf(); mat .Translate(0.5f, 0, 0.5f) .RotateYDeg(Block.Shape.rotateY - 90) .Translate(-0.5f, 0, -0.5f) ; spoutPos = mat.TransformVector(new Vec4f(8f / 16f, 7.5f / 16f, 3.5f / 16f, 1)).XYZ; var steamposoffmin = mat.TransformVector(new Vec4f(6 / 16f, 13 / 16f, 9 / 16f, 1)).XYZ; var steamposoffmax = mat.TransformVector(new Vec4f(10 / 16f, 13 / 16f, 13 / 16f, 1)).XYZ; steamposmin = Pos.ToVec3d().Add(steamposoffmin); steamposmax = Pos.ToVec3d().Add(steamposoffmax); }
public void InitForUse(float rotateYDeg) { Matrixf mat = new Matrixf(); mat.RotateYDeg(rotateYDeg); BlockCodes = new Dictionary <int, AssetLocation>(); TransformedOffsets = new List <BlockOffsetAndNumber>(); foreach (var val in BlockNumbers) { BlockCodes[val.Value] = val.Key; } for (int i = 0; i < Offsets.Count; i++) { Vec4i offset = Offsets[i]; Vec4f offsetTf = new Vec4f(offset.X, offset.Y, offset.Z, 0); Vec4f tfedOffset = mat.TransformVector(offsetTf); TransformedOffsets.Add(new BlockOffsetAndNumber() { X = (int)Math.Round(tfedOffset.X), Y = (int)Math.Round(tfedOffset.Y), Z = (int)Math.Round(tfedOffset.Z), W = offset.W }); } }
// KalmanInitializef is called for initializing the initial estimate public void KalmanInitializef(Matrixf stateTransMatrix, Matrixf controlMatrix, Matrixf inputVar, Matrixf procNoiseVector, Matrixf obsvMatrix, Matrixf measNoiseVector) { // assign the variables if (stateTransMatrix.rows != Ff.rows || stateTransMatrix.columns != Ff.columns) { throw new ArgumentException("Can not assign the state transition matrix with different rows or columns.", nameof(stateTransMatrix)); } else { Ff = stateTransMatrix; } if (controlMatrix.rows != Gf.rows || controlMatrix.columns != Gf.columns) { throw new ArgumentException("Can not assign the control matrix with different rows or columns.", nameof(controlMatrix)); } else { Gf = controlMatrix; } if (inputVar.rows != uf.rows || inputVar.columns != uf.columns) { throw new ArgumentException("Can not assign the input variable with different rows or columns.", nameof(inputVar)); } else { uf = inputVar; } if (procNoiseVector.rows != wf.rows || procNoiseVector.columns != wf.columns) { throw new ArgumentException("Can not assign the process noise vector with different rows or columns.", nameof(procNoiseVector)); } else { wf = procNoiseVector; } if (obsvMatrix.rows != Hf.rows || obsvMatrix.columns != Hf.columns) { throw new ArgumentException("Can not assign the observation matrix with different rows or columns.", nameof(obsvMatrix)); } else { Hf = obsvMatrix; } if (measNoiseVector.rows != vf.rows || measNoiseVector.columns != vf.columns) { throw new ArgumentException("Can not assign the measurement noise vector with different rows or columns.", nameof(measNoiseVector)); } else { vf = measNoiseVector; } // construct the process noise uncertainty and measurement noise uncertainty Qf = Matrixf.Mul(wf, Matrixf.Transpose(wf)); Rf = Matrixf.Mul(vf, Matrixf.Transpose(vf)); // calculate the initial estimate(initial state vector and estimate uncertainty) for updating iteration KalmanPredictf(); }
public void PinTo(Entity toEntity, Vec3f pinOffset) { pinned = true; pinnedTo = toEntity; pinnedToEntityId = toEntity.EntityId; pinnedToOffset = pinOffset; pinnedToOffsetStartYaw = toEntity.SidedPos.Yaw; pinOffsetTransform = Matrixf.Create(); pinnedToBlockPos = null; MarkDirty(); }
void updateLocalEyePosImmersiveFpMode() { AttachmentPointAndPose apap = AnimManager.Animator.GetAttachmentPointPose("Eyes"); AttachmentPoint ap = apap.AttachPoint; float[] ModelMat = Mat4f.Create(); Matrixf tmpModelMat = new Matrixf(); float bodyYaw = BodyYaw; float rotX = Properties.Client.Shape != null ? Properties.Client.Shape.rotateX : 0; float rotY = Properties.Client.Shape != null ? Properties.Client.Shape.rotateY : 0; float rotZ = Properties.Client.Shape != null ? Properties.Client.Shape.rotateZ : 0; float bodyPitch = WalkPitch; float lookOffset = (SidedPos.Pitch - GameMath.PI) / 9f; bool wasHoldPos = holdPosition; holdPosition = false; for (int i = 0; i < AnimManager.Animator.RunningAnimations.Length; i++) { RunningAnimation anim = AnimManager.Animator.RunningAnimations[i]; if (anim.Running && anim.EasingFactor > anim.meta.HoldEyePosAfterEasein) { if (!wasHoldPos) { prevAnimModelMatrix = (float[])apap.AnimModelMatrix.Clone(); } holdPosition = true; break; } } tmpModelMat .Set(ModelMat) .RotateX(SidedPos.Roll + rotX * GameMath.DEG2RAD) .RotateY(bodyYaw + (180 + rotY) * GameMath.DEG2RAD) .RotateZ(bodyPitch + rotZ * GameMath.DEG2RAD) .Mul(holdPosition ? prevAnimModelMatrix : apap.AnimModelMatrix) .Scale(Properties.Client.Size, Properties.Client.Size, Properties.Client.Size) .Translate(-0.5f, 0, -0.5f) .Translate(ap.PosX / 16f - lookOffset, ap.PosY / 16f - lookOffset / 1.3f, ap.PosZ / 16f) ; float[] pos = new float[4] { 0, 0, 0, 1 }; float[] endVec = Mat4f.MulWithVec4(tmpModelMat.Values, pos); LocalEyePos.Set(endVec[0], endVec[1], endVec[2]); }
public RiftRenderer(ICoreClientAPI capi, List <Rift> rifts) { this.capi = capi; this.rifts = rifts; capi.Event.RegisterRenderer(this, EnumRenderStage.AfterBlit, "rendertest"); MeshData mesh = QuadMeshUtil.GetQuad(); meshref = capi.Render.UploadMesh(mesh); matrixf = new Matrixf(); capi.Event.ReloadShader += LoadShader; LoadShader(); modsys = capi.ModLoader.GetModSystem <ModSystemRifts>(); }
// KalmanCorrectf is called for correcting the predict of the pre-state(first update for every iteration) public void KalmanCorrectf(Matrixf measurement) { // update the output vector(measurement result) if (measurement.rows != zf.rows || measurement.columns != zf.columns) { throw new ArgumentException("Can not update the measurement with different rows or columns.", nameof(measurement)); } else { zf = measurement; } // compute the kalman gain and correct the discrete state and estimate uncertainty Kf = Matrixf.Mul(Matrixf.Mul(Pf, Matrixf.Transpose(Hf)), Matrixf.Inverse(Matrixf.Mul(Matrixf.Mul(Hf, Pf), Matrixf.Transpose(Hf)) + Rf)); xf = xf + Matrixf.Mul(Kf, (zf - Matrixf.Mul(Hf, xf))); Pf = Matrixf.Mul(Matrixf.Mul((Matrixf.Identity(xf.rows, xf.rows) - Matrixf.Mul(Kf, Hf)), Pf), Matrixf.Transpose(Matrixf.Identity(xf.rows, xf.rows) - Matrixf.Mul(Kf, Hf))) + Matrixf.Mul(Matrixf.Mul(Kf, Rf), Matrixf.Transpose(Kf)); }
static void initRotations() { for (int i = 0; i < 4; i++) { Matrixf m = new Matrixf(); m.Translate(0.5f, 0.5f, 0.5f); m.RotateYDeg(i * 90); m.Translate(-0.5f, -0.5f, -0.5f); Vec3f[] poses = candleWickPositionsByRot[i] = new Vec3f[candleWickPositions.Length]; for (int j = 0; j < poses.Length; j++) { Vec4f rotated = m.TransformVector(new Vec4f(candleWickPositions[j].X / 16f, candleWickPositions[j].Y / 16f, candleWickPositions[j].Z / 16f, 1)); poses[j] = new Vec3f(rotated.X, rotated.Y, rotated.Z); } } }
public CmdResult Execute(ExtendCmdData cmdData, ref string message) { var mainForm = cmdData.MainForm as Form; var viewForm = cmdData.ViewForm as IViewForm; if (viewForm == null) { return(CmdResult.Cancel); } var osgView = viewForm.View as ZfOsgViewCtrl; var osgObj = osgView.OsgObj; // 读取模型 string osgFileName; if (!DialogUtil.OpenOSG(out osgFileName)) { return(CmdResult.Cancel); } var node = OsgDB._.readNodeFile(osgFileName); var sequence = new Sequence(); for (int i = 0; i < 24 * 2; i++) { var matrixd = Matrixf.rotate((float)(Math.PI / 12 * 2) * i, new Vec3d(0, 0, 1)); var matrixTransform = new MatrixTransform(matrixd); matrixTransform.addChild(node); sequence.addChild(matrixTransform, i); } //设置帧动画持续的时间 sequence.setInterval(Sequence.LoopMode.LOOP, 0, -1); //设置播放的速度及重复的次数 sequence.setDuration(1.0f / 24, 10); sequence.setLoopMode(Sequence.LoopMode.LOOP); sequence.setMode(Sequence.SequenceMode.START); sequence.Name = "sequence"; osgObj.AddOrReplaceModel("Models", sequence); return(CmdResult.Succeed); }
public Matrixf Kf; // kalman gain(nx x nz) // initialize the KalmanFilter class(float type) public KalmanFilterf(int nx, int nz, int nu, Matrixf initStateVector, Matrixf initEstimateUncertainty) { // define the dimensions of state vector, process noise vector and measurement noise vector nxf = nx; nzf = nz; nuf = nu; // initialize the variables xf = new Matrixf(nxf, 1); zf = new Matrixf(nzf, 1); Ff = new Matrixf(nxf, nxf); uf = new Matrixf(nuf, 1); Gf = new Matrixf(nxf, nuf); Pf = new Matrixf(nxf, nxf); Qf = new Matrixf(nxf, nxf); Rf = new Matrixf(nzf, nzf); wf = new Matrixf(nxf, 1); vf = new Matrixf(nzf, 1); Hf = new Matrixf(nzf, nxf); Kf = new Matrixf(nxf, nzf); // assign the initial state vector and estimate uncertainty if (initStateVector.rows != xf.rows || initStateVector.columns != xf.columns) { throw new ArgumentException("Can not assign the initial state vector with different rows or columns.", nameof(initStateVector)); } else { xf = initStateVector; } if (initEstimateUncertainty.rows != Pf.rows || initEstimateUncertainty.columns != Pf.columns) { throw new ArgumentException("Can not assign the initial estimate uncertainty with different rows or columns.", nameof(initEstimateUncertainty)); } else { Pf = initEstimateUncertainty; } }
// KalmanPredictf is called for predicting the state(second update for every iteration) public void KalmanPredictf() { // predict the discrete state and covariance xf = Matrixf.Mul(Ff, xf) + Matrixf.Mul(Gf, uf); Pf = Matrixf.Mul(Matrixf.Mul(Ff, Pf), Matrixf.Inverse(Ff)) + Qf; }
public CmdResult Execute(ExtendCmdData cmdData, ref string message) { var mainForm = cmdData.MainForm as Form; var viewForm = cmdData.ViewForm as IViewForm; if (viewForm == null) { return(CmdResult.Cancel); } var osgView = viewForm.View as ZfOsgViewCtrl; var osgObj = osgView.OsgObj; var skelroot = new Skeleton(); // 骨骼动画 skelroot.setDefaultUpdateCallback(); var root = new Bone(); // 骨骼 root.setInvBindMatrixInSkeletonSpace(Matrixd.inverse(Matrixd.translate(-1.0f, 0.0f, 0.0f))); root.setName("root"); var pRootUpdate = new UpdateBone("root"); // 骨骼更新器 pRootUpdate.getStackedTransforms().push_back(new StackedTranslateElement("translate", new Vec3f(-1.0f, 0.0f, 0.0f))); root.setUpdateCallback(pRootUpdate); var right0 = new Bone(); right0.setInvBindMatrixInSkeletonSpace(Matrixd.inverse(Matrixd.translate(0.0f, 0.0f, 0.0f))); right0.setName("right0"); var pRight0Update = new UpdateBone("right0"); pRight0Update.getStackedTransforms().push_back(new StackedTranslateElement("translate", new Vec3f(1.0f, 0.0f, 0.0f))); pRight0Update.getStackedTransforms().push_back(new StackedRotateAxisElement("rotate", new Vec3f(0.0f, 0.0f, 1.0f), 0.0)); right0.setUpdateCallback(pRight0Update); var right1 = new Bone(); right1.setInvBindMatrixInSkeletonSpace(Matrixd.inverse(Matrixd.translate(1.0f, 0.0f, 0.0f))); right1.setName("right1"); var pRight1Update = new UpdateBone("right1"); pRight1Update.getStackedTransforms().push_back(new StackedTranslateElement("translate", new Vec3f(1.0f, 0.0f, 0.0f))); pRight1Update.getStackedTransforms().push_back(new StackedRotateAxisElement("rotate", new Vec3f(0.0f, 0.0f, 1.0f), 0.0)); right1.setUpdateCallback(pRight1Update); root.addChild(right0); right0.addChild(right1); skelroot.addChild(root); Group scene = new Group(); BasicAnimationManager manager = new BasicAnimationManager(); scene.setUpdateCallback(manager); Animation anim = new Animation(); { var keys0 = new FloatKeyframeContainer(); // 关键帧容器 keys0.push_back(new FloatKeyframe(0.0, 0.0f)); keys0.push_back(new FloatKeyframe(3.0, (float)MathUtil.PI_2)); keys0.push_back(new FloatKeyframe(6.0, (float)MathUtil.PI_2)); var sampler = new FloatLinearSampler(); // 线性采样器 sampler.setKeyframeContainer(keys0); var channel = new FloatLinearChannel(sampler); // 通道 channel.setName("rotate"); channel.setTargetName("right0"); anim.addChannel(channel); } { var keys1 = new FloatKeyframeContainer(); // 关键帧容器 keys1.push_back(new FloatKeyframe(0.0, 0.0f)); keys1.push_back(new FloatKeyframe(3.0, 0.0f)); keys1.push_back(new FloatKeyframe(6.0, (float)MathUtil.PI_2)); var sampler = new FloatLinearSampler(); // 线性采样器 sampler.setKeyframeContainer(keys1); var channel = new FloatLinearChannel(sampler); // 通道 channel.setName("rotate"); channel.setTargetName("right1"); anim.addChannel(channel); } manager.registerAnimation(anim); manager.buildTargetReference(); // let's start ! manager.playAnimation(anim); // we will use local data from the skeleton MatrixTransform rootTransform = new MatrixTransform(); rootTransform.setMatrix(Matrixf.rotate((float)MathUtil.PI_2, new Vec3f(1.0f, 0.0f, 0.0f))); right0.addChild(createAxis()); right0.setDataVariance(Osg.Object.DataVariance.DYNAMIC); right1.addChild(createAxis()); right1.setDataVariance(Osg.Object.DataVariance.DYNAMIC); MatrixTransform trueroot = new MatrixTransform(); //trueroot.setMatrix(new Matrixf(root.getMatrixInBoneSpace().ptr())); trueroot.setMatrix(root.getMatrixInBoneSpace()); trueroot.addChild(createAxis()); trueroot.addChild(skelroot); trueroot.setDataVariance(Osg.Object.DataVariance.DYNAMIC); rootTransform.addChild(trueroot); scene.addChild(rootTransform); RigGeometry geom = createTesselatedBox(4, 4.0f); Geode geode = new Geode(); geode.Name = "2"; geode.addDrawable(geom); skelroot.addChild(geode); Vec3Array src = new Vec3Array(geom.getSourceGeometry().getVertexArray()); geom.setDataVariance(Osg.Object.DataVariance.DYNAMIC); initVertexMap(root, right0, right1, geom, src); scene.Name = "1"; osgObj.AddOrReplaceModel("Models", scene); osgObj.SetView(ViewMode.ShowAll); return(CmdResult.Succeed); }
public void RenderLiquidItemStackGui(ItemSlot inSlot, ItemRenderInfo renderInfo, Matrixf modelMat, double posX, double posY, double posZ, float size, int color, bool rotate = false, bool showStackSize = true) { ItemStack itemstack = inSlot.Itemstack; WaterTightContainableProps props = BlockLiquidContainerBase.GetContainableProps(itemstack); capi.Render.RenderMesh(renderInfo.ModelRef); if (showStackSize) { float litreFloat = (float)itemstack.StackSize / props.ItemsPerLitre; string litres; if (litreFloat < 0.1) { litres = Lang.Get("{0} mL", (int)(litreFloat * 1000)); } else { litres = Lang.Get("{0:0.##} L", litreFloat); } float mul = size / (float)GuiElement.scaled(32 * 0.8f); var texttex = GetOrCreateLitreTexture(litres, size, mul); capi.Render.GlToggleBlend(true, EnumBlendMode.PremultipliedAlpha); capi.Render.Render2DLoadedTexture(texttex, (int)(posX + size + 1 - texttex.Width - GuiElement.scaled(1)), (int)(posY + size - texttex.Height + mul * GuiElement.scaled(3) - GuiElement.scaled(5)), (int)posZ + 60 ); capi.Render.GlToggleBlend(true, EnumBlendMode.Standard); } }
public CmdResult Execute(ExtendCmdData cmdData, ref string message) { var mainForm = cmdData.MainForm as Form; var viewForm = cmdData.ViewForm as IViewForm; if (viewForm == null) { return(CmdResult.Cancel); } var osgView = viewForm.View as ZfOsgViewCtrl; var osgObj = osgView.OsgObj; var geode = new Geode(); geode.addDrawable(new ShapeDrawable(new Box(new Vec3f(0, 0, 0), 0.5f))); var trans = new MatrixTransform(); trans.Name = "AnimatedNode"; trans.setDataVariance(Osg.Object.DataVariance.DYNAMIC); trans.setMatrix(Matrixf.identity()); trans.addChild(geode); var root = new Group(); root.addChild(trans); var grp = new Group() { Name = "1" }; grp.addChild(root); var updatecb = new UpdateMatrixTransform("AnimatedCallback"); updatecb.getStackedTransforms().push_back(new StackedTranslateElement("position")); updatecb.getStackedTransforms().push_back(new StackedRotateAxisElement("euler", new Vec3f(1, 0, 0), 0)); trans.setUpdateCallback(updatecb); var mng = new BasicAnimationManager(); grp.setUpdateCallback(mng); var channelAnimation1 = new Vec3LinearChannel(); //name of the AnimationUpdateCallback channelAnimation1.setTargetName("AnimatedCallback"); //name of the StackedElementTransform for position modification channelAnimation1.setName("position"); //Create keyframes for (in this case linear) interpolation of a Vec3 var keyframeContainer = channelAnimation1.getOrCreateSampler().getOrCreateKeyframeContainer(); keyframeContainer.push_back(new Vec3Keyframe(0, new Vec3f(0, 0, 0))); keyframeContainer.push_back(new Vec3Keyframe(2, new Vec3f(1, 1, 0))); var anim1 = new Animation(); anim1.addChannel(channelAnimation1); anim1.setPlayMode(Animation.PlayMode.PPONG); //define the channel for interpolation of a float angle value var channelAnimation2 = new FloatLinearChannel(); //name of the AnimationUpdateCallback channelAnimation2.setTargetName("AnimatedCallback"); //name of the StackedElementTransform for position modification channelAnimation2.setName("euler"); //Create keyframes for (in this case linear) interpolation of a Vec3 var keyframeContainer2 = channelAnimation2.getOrCreateSampler().getOrCreateKeyframeContainer(); keyframeContainer2.push_back(new FloatKeyframe(0, 0)); keyframeContainer2.push_back(new FloatKeyframe(1.5, (float)(2 * Math.PI))); var anim2 = new Animation(); anim2.addChannel(channelAnimation2); anim2.setPlayMode(Animation.PlayMode.LOOP); // We register all animation inside the scheduler mng.registerAnimation(anim1); mng.registerAnimation(anim2); //start the animation mng.playAnimation(anim1); mng.playAnimation(anim2); osgObj.AddOrReplaceModel("Models", grp); osgObj.SetView(ViewMode.ShowAll); return(CmdResult.Succeed); }