How to make a very large skybox? (babylon.js) - babylonjs

How can I make a very large skybox?
Example:
var skybox = BABYLON.Mesh.CreateBox("skyBox", 15000.0, this.scene);
The result is bad:

The first thing I suggest is to reduce the scale factor of your spaceship and planet models. It seems that having a SkyBox size larger than 10000 causes the ugly texture seams/tearing of the Skybox at particular camera angles and distances. So bring everything down in scale if possible to make more room inside the limits of the Skybox perimeter.
Next try this: set .infiniteDistance = true to keep the Skybox away from the camera, and also set .renderingGroupId = 0 on the Skybox. Lastly, set .renderingGroupId = 1 or more, on all the models and objects to help stop them from disappearing into thin air.
var skybox = BABYLON.MeshBuilder.CreateBox("skyBox", {size:10000.0},
this.scene);
skybox.infiniteDistance = true;
skybox.renderingGroupId = 0;
...and for models and sprite objects...
myModel.renderingGroupId = 1; /* greater than 0 */
These little tricks helped me to achieve a to-scale solar system simulation, but may not work in all cases.

Hello you need to increase camera.maxZ to a value larger than your skybox.

Related

Move a KinematicBody2D to a known location (godot)

Im making a platformer in godot and in the physics process im getting the players location so I can move the enemy to it(its in the enemy's script but I can not figure out how to move it there im using get_node("/root/World/Player").get_position() to get the location
but when I move and slide towards the player it gives me an error.(btw it is a platformer so it would be nice if the method added gravity)
Invalid type function 'move_and_slide' in base 'KinematicBody2D (enemy.gd)'. Cannot convert argument 2 from float to Vector2.
(It would be nice if the way it
Let us start by looking at the documentation of move_and_slide. This is the signature of the function:
Vector2 move_and_slide ( Vector2 linear_velocity, Vector2 up_direction=Vector2( 0, 0 ), bool stop_on_slope=false, int max_slides=4, float floor_max_angle=0.785398, bool infinite_inertia=true )
Notice:
The first parameter is a velocity vector.
The second parameter is an up vector.
Thus, this function does not work with a position.
And the error you are getting is because you are passing a float on the up parameter.
Why does move_and_slide take an up vector? It is because move_and_slide updates the values you get from is_on_ceiling, is_on_floor and is_on_wall. And how does it know what is a ceiling, a floor or a wall? That's right, it needs to know what way it up. If you let the up vector at ZERO (or just not pass it, since that's the default value), they are all considered walls (and this is OK for a top down game).
Now, you want to do a platformer game, presumably a side scroller. Most likely you want to pass Vector2.UP as second parameter. And that should fix the error.
However, you are sneaking another question in there. One more suited for gamedev.stackexchange.com. You can ask question there (and it does not have to be that you are getting an error).
So, you want to implement a kinematic body with gravity that chases the player. Let us start with the gravity…
The run of the mill code for a kinematic body with gravity looks like this:
extends KinematicBody2D
export(Vector2) var velocity:Vector2
export(float) var gravity:float = 100
func _physics_process(delta:float) -> void:
velocity.y += gravity * delta
velocity = move_and_slide(velocity, Vector2.UP)
Ok, gravity is probably not 100. But that is the basic structure of the code. Note the distance units - being a 2D game - are in pixels, and delta is in seconds. Thus, gravity is in pixels per second squared.
And you want to chase the player avatar. In order to implement that I'll do the following changes:
Have a reference to the player avatar.
Split velocity into vertical and horizontal components.
Have an horizontal speed.
extends KinematicBody2D
export(NodePath) var player_path:NodePath = #"/root/World/Player"
export(float) var horizontal_speed:float = 100
export(float) var gravity:float = 100
onready var player:Node2D = get_node(player_path)
var _velocity:float = 0
func _physics_process(delta:float) -> void:
_velocity.y += gravity * delta
_velocity = move_and_slide(_velocity, Vector2.UP)
var direction_to_player = transform.origin.direction_to(player.transform.origin)
_velocity.x = direction_to_player.x * horizontal_speed
This code uses a NodePath to find the player avatar. Which it queries on ready, and uses that reference from there on. Assuming the player is always there, that is no problem.
The horizontal_speed specifies how fast it moves horizontally towards the player. In pixels per second.
If you don't want it to change velocity while it is in the air, we can do that too:
extends KinematicBody2D
export(NodePath) var player_path:NodePath = #"/root/World/Player"
export(float) var horizontal_speed:float = 100
export(float) var gravity:float = 100
onready var player:Node2D = get_node(player_path)
var _velocity:Vector2 = Vector2.ZERO
func _physics_process(delta:float) -> void:
_velocity.y += gravity * delta
_velocity = move_and_slide(_velocity, Vector2.UP)
if is_on_floor():
var direction_to_player = global_transform.origin.direction_to(player.global_transform.origin)
_velocity.x = direction_to_player.x * horizontal_speed
Notice I'm using global_transform.origin. You could also use global_position. Don't use transform.origin nor position, because they are relative to the parent node. And if the parent is not the same, you are going to get a wrong direction. *I bias towards using transform because
Notice also I'm using is_on_floor after move_and_slide, so I get the updated value. I strongly encourage this pattern: gravity, move_and_slide, decisions.
This is not going to jump or climb ladders or anything like that. It will also get stuck on walls. It has nothing resembling path finding or obstacle avoidance. So, as you can imagine, it can get quite complex depending on what you want to do. However, it grows from there. I know little of the behavior you want to give these kinematic bodies, beyond that you want them to go to the player, using mode_and_slide and with gravity, I have no idea. Thus, I cannot help you further.

How to avoid network graph nodes overlapping?

I was using Visjs and displaying rectanglar nodes with text. Some of the nodes can have a couple of lines of text so I added a heuristic algorithm to work out roughly where the line breaks should go to avoid very wide, single line chunks of text in very wide but very short nodes.
The trouble is, even with physics turned on, I still get overlapping nodes.
Is it possible to tell the layout engine that, under no circumstances (or physics models), should any two nodes overlap?
Well, check out the physics configuration example: as you can see, barnesHut solver has avoidOverlap property which prevents overlapping even when springConstant is equal to zero. Try this:
var options = {
"physics": {
"barnesHut": {
"springConstant": 0,
"avoidOverlap": 0.2
}
}
}
and tweak the constants to fit your needs (the example linked above is useful for that).
From its documentation:
Accepted range: [0 .. 1]. When larger than 0, the size of the node is taken into account. The distance will be calculated from the radius of the encompassing circle of the node for both the gravity model. Value 1 is maximum overlap avoidance.
To be noted, though: I've seen a recommendation to start with low values of avoidOverlap (like 0.1) to simplify the task for the solver. I can't recall where exactly I've read this.
I used levelSeparation to adjust the horizontal node distance, and nodeDistance to adjust the vertical node distance:
const options = {
layout: {
hierarchical: {
direction: 'LR',
sortMethod: 'directed',
levelSeparation: 300,
},
},
physics: {
hierarchicalRepulsion: {
nodeDistance: 140,
},
},
...
}

Mathematically scale large elements lesser then small elements

10 elements with the class xxx have different widths and heights. Putting transform: scale(1.1) enlarges the big ones clearly but the small ones barely show difference. This is bad UX. The mathematical question is how to make the bigger elements scale less then the smaller ones:
width 10 should get scale 1.1
width 5 should get scale 1.2
How can i mathematically solve this?
The question lacks context and details, so it is hard to give a generally meaningful answer. However, the given examples indicate the following solution:
x_new = 1 + 1/x_old
Where x_old is the input value, i.e. 10 or 5.
Using logarithmic scaling instead of just 1/x_old might be another option, depending on the context.
To illustrate the scenarios i made these pens:
non logarithmic scale: http://codepen.io/anon/pen/bwRVpj
logarhitmic scale: http://codepen.io/anon/pen/VKWLJK
var inlineStyle = ''
var divs = document.getElementsByTagName('div')
var len = divs.length
while(len--) {
var elWidth = divs[len].offsetWidth
var scale = 1+9/elWidth
inlineStyle += `#${divs[len].id}:hover {
transform: scale(${scale})
}`
}
document.getElementById('lolStyle').innerHTML = inlineStyle

2D Game colision response

So I am writing a game, but I have come to the part where i need to do some collision response, and I have been stumped. I have an algorithm that finds the objects collision angle, and collision depth meaning how much the two objects over lap. I understand what i want to do and that is to find a perpendicular vector to the collision angle and push back the object that is colliding by it's collision depth, but I just can't seem to write it correctly.
Here is the code I'm working with for the time being.
var collision:Object = collisions[i];
var angle:Number = collision.angle;
var overlap:Number = collision.overlapping.length;
trace(overlap);
trace(angle);
var moveX = Math.cos(angle) * overlap;
var moveY = Math.sin(angle) * overlap;
obj2.x -= moveX;
obj2.y += moveY;
basically I just want the object that is colliding with the wall to stop when it hits it.
any help would be greatly appreciated.
I worked on elastic collision with flash as3 once.I tried to fix overlap a lot of.But i could'nt solved it completely.They did not overlapping normally but if you forced enought, they overlapping.
if you want look at my work, i uploaded my codes.You can download and look at my code.
And if you solve this problem completely, please tell me solution.
swf(with friction, it's more problem) : http://nafiz.in/collision/carpisma.swf
swf(without friction, it's little problem than first.) : http://nafiz.in/collision/carpisma_surtunmesiz.swf
q : add a ball at mouse location.
w, a,s,d : controll #1 ball.
Click with mouse without relase and move mouse and relase. You selected balls.
When you press space, selected balls will go mouse location.
Cods : http://nafiz.in/collision/collision.rar
i hope you solve.
So after a few hours of tweaking the code, I came up with the solution that works well. here is my new code:
public function Colisions(obj1,obj2) {
var collisions:Array=MyCollision.checkCollisions();
for (var i = 0; i < collisions.length; i++) {
var collision:Object=collisions[i];
var angle:Number=collision.angle;
var overlap:Number=collision.overlapping.length;
// finds the amount in x and y coordinates to move the ball back, and it devides overlap by 20 so that the ball does not jump as much.
var moveX=Math.cos(angle)*(overlap/20);
var moveY=Math.sin(angle)*(overlap/20);
// sets the ball to it's original location before the colision.
obj2.x=obj2.x-moveX;
obj2.y=obj2.y-moveY;
}
}
just as a side note I am using CDK which stands for the collision detection toolkit as the algorithm that finds the collisions and the info associated with the collisions.

Flex Charts: Can you use a minimum/maximum point from an IAxis for Cartesian Data Canvas to draw the entire width of the chart?

I have a chart with a DateTime axis as my horizontal and a Linear Axis for my vertical inside a Adobe Flex Line Chart. I want to use a Cartesian Data Canvas as a background element and draw custom set of background graphics mostly rectangles. When I have more than a single data point, the graphics work perfectly since they are supposed to span the width of the entire chart.
When I have only a single data point, however, I can't seem to get the rectangles to draw. Since I want my rectangles to span the entire width of the chart, I was thinking that I could get the x-coordinates from my axis, but this isn't working.
var canvasWidth:Number = chtCanvas.width;
var canvasHeight:Number = chtCanvas.height;
var minPt:Array;
var maxPt:Array;
var minPtDate:Date;
var maxPtDate:Date;
var minPtComplete:Point;
var maxPtComplete:Point;
// This works fine when there is more than 1 data point
minPt = chtCanvas.localToData(new Point(0, 0));
maxPt = chtCanvas.localToData(new Point(canvasWidth,canvasHeight));
//This does return a date object, but wont draw below
minPtDate = axisDate.minimum;
maxPtDate = axisDate.maximum;
//This returns NaN for the x
minPtComplete = chtCanvas.dataToLocal(minPtDate, axisSalary.minimum);
maxPtComplete = chtCanvas.dataToLocal(maxPtDate, axisSalary.maximum);
// Also tried this. Also returns NaN for the x value
//minPtComplete = chtCanvas.dataToLocal(axisDate.minimum, axisSalary.minumum);
//maxPtComplete = chtCanvas.dataToLocal(axisDate.maximum, axisSalary.maximum);
My actual drawing method is as follows:
// Tried this, works with points >2, does not draw with single data point
chtCanvas.drawRect(minPt[0], detail[i].MaxValue, maxPt[0], detail[i].MinValue);
//tried this, no effect with single point
//chtCanvas.drawRect(minPtDate, detail[i].MaxValue, maxPtDate, detail[i].MinValue);
// Tried this, no effect with single point
//chtCanvas.drawRect(minPtDate, minPt[1], maxPtDate, detail[i].MinValue);
// Tried this also
//chtCanvas.drawRect(minPtComplete.x, detail[i].MaxValue, maxPtComplete.x, detail[i].MinValue);
In this example, detail is an array collection of salary values and Im using the data value in the array to determine the vertical bounds of my rectangles.
I need to draw the rectangles the entire width of the chart (even when there is only a single data point). Thanks
Thanks to Heikki for his help. The following code works to use the axis values to draw on your Cartesian Data Canvas:
chtCanvas.drawRect(axisDate.minimum as Date, axisSalary.maximum, axisDate.maximum as Date, axisSalary.minimum);
Casting the values as Date really helped. The rest of the code used above is unecessary.
One thing to note, I was using a DateFormatter to format the date values from my data. What I didn't consider was that when using a DateTimeAxis, Flex will automatically add in extra dates to display on the axis. In my case, I was using a custom parse function to create MY points, but wasnt considering the points Flex was creating and also passing to my parse function (Therefore, they were not getting parsed correctly). Once I corrected this, the values laid out correctly in the case of multiple data points. I'm still having a bit of an issue with single data points and them not filling the chart entirely, but they are now drawing.
UPDATE:
Although there are signs of life, the minimum and maximum are still not drawing the entire width of the chart in some cases depending on the dataUnits and labelUnits combination.
UPDATE #2: SOLVED
Ok, so the axis does work as minimum/maximum values for the Cartesian Data Canvas but there is something important to remember. For a single point (and probably for multiple points as well, I just couldnt visually see the difference), when using a custom DateTimeAxis parse function such as what was in the Adobe Flex ASDoc tutorials:
private function axisDateParseFunction(item:String):Date
{
var inputDate:String = item;
inputDate = fmtDate.format(inputDate);
var newDate:Date = new Date();
if(inputDate)
{
var a:Array = inputDate.split('/');
newDate.fullYear = a[2];
newDate.month = a[0] - 1;
newDate.date = a[1];
newDate.hours = 0;
newDate.hoursUTC = 0;
newDate.minutes = 0;
newDate.minutesUTC = 0;
newDate.seconds = 0;
newDate.secondsUTC = 0;
newDate.milliseconds = 0;
newDate.millisecondsUTC = 0;
}
return newDate;
}
You MUST remember to set the UTC values as shown above also. Since the DateTimeAxis uses date AND time, when you create new Date objects, their time values also get set to the local system time. Remember to set those values to zero also or you will get points that dont exactly line up with your axis labels.

Resources