// start of the main loop public override int update() { ifps = Game.get().getIFps(); if (elapsedTime < 0.0f) { currentObjectsScale = new vec3(Game.get().getRandomFloat(0.8f, 1.2f)); forwardDirection = forwardDirection * MathLib.rotateZ(60); elapsedTime = changeInterval; } elapsedTime -= ifps; if (app.clearMouseButtonState(App.BUTTON_RIGHT) == 1) { newSelection = GetObjectUnderCursor(Game.get().getPlayer(), app.getMouseX(), app.getMouseY(), 100f); SelectObject(newSelection, oldSelection); } if (app.getKeyState('q') == 1 && Unigine.Console.get().getActivity() != 1) { app.exit(); } UpdateObjects(); UpdateLights(); return(1); }
public int SelectObject(Unigine.Object new_select_object, Unigine.Object old_select_object) { if (new_select_object != null) { if (new_select_object.getProperty(0).findParameter("selected") != -1) { new_select_object.getProperty(0).setParameterInt(new_select_object.getProperty(0).findParameter("selected"), 1); if (old_select_object != null) { //oldSelection1.getProperty().findParameter("selected"); old_select_object.getProperty(0).setParameterInt(old_select_object.getProperty(0).findParameter("selected"), 0); } oldSelection = new_select_object; //Log.message("\n" + new_select_object.getName() + " is selected! \n"); } return(1); } return(0); }
private void TryMoveDown(float ifps) { vec3 moveImpulseXY = moveImpulse - vec3.UP * MathLib.Dot(vec3.UP, moveImpulse); Vec3 pos1 = position + (moveImpulseXY.Normalized + vec3.UP) * shape.Radius; Vec3 pos2 = pos1 - vec3.UP * shape.Radius; WorldIntersectionNormal intersection = new WorldIntersectionNormal(); Unigine.Object hitObj = World.GetIntersection(pos1, pos2, contactsIntersectionMask, intersection); if (hitObj) { float angle = MathLib.GetAngle(vec3.UP, intersection.Normal); if (autoSteppingCancelAngle < angle && angle < 90.0f) { position -= autoSteppingOffset; usedAutoStepping = false; return; } } vec3 velocityXY = velocity - vec3.UP * MathLib.Dot(vec3.UP, velocity); pos1 = position + (velocityXY.Normalized + vec3.UP) * shape.Radius; pos2 = pos1 - vec3.UP * shape.Radius; hitObj = World.GetIntersection(pos1, pos2, contactsIntersectionMask, intersection); if (hitObj) { float angle = MathLib.GetAngle(vec3.UP, intersection.Normal); if (autoSteppingCancelAngle < angle && angle < 90.0f) { position -= autoSteppingOffset; usedAutoStepping = false; return; } } // this correction allows to avoid jittering on large stairs if (lastStepHeight > shape.Radius) { if (GravityMultiplier > 1.0f) { lastStepHeight = shape.Radius / GravityMultiplier - Physics.PenetrationTolerance; } else { lastStepHeight = shape.Radius - Physics.PenetrationTolerance; } } // try to drop down the player position -= new vec3(zAxis * lastStepHeight); autoSteppingOffset -= new vec3(zAxis * lastStepHeight); // move (apply "position") dummy.Transform = GetBodyTransform(); // find collisions with the capsule shape.GetCollision(contacts, 0.0f); if (contacts.Count == 0) { return; } int contactsCount = MathLib.Min(contacts.Count, contactsBufferSize); float inumContacts = 1.0f / MathLib.Itof(contactsCount); // push up (if collisions exists) for (int i = 0; i < contactsCount; i++) { ShapeContact c = contacts[i]; position += new vec3(zAxis * (MathLib.Max(c.Depth, 0.0f) * inumContacts * MathLib.Dot(zAxis, c.Normal))); if (MathLib.Dot(c.Normal, vec3.UP) > 0.5f && MathLib.Dot(new vec3(c.Point - shape.BottomCap), vec3.UP) < 0.0f) { IsGround = true; } } if (renderDownPassContacts) { foreach (var c in contacts) { Visualizer.RenderVector(c.Point, c.Point + c.Normal, new vec4(0, 1, 0, 1)); } } }