sample code to use tiled resource technology in d3d11.2? - directx

i got a strange result in calling UpdateTileMapping and UpdateTiles every frame like this which as same as the Mars Tiled Resource Sample do:
void CalledEveryFrame()
{
vector<D3D11_TILED_RESOURCE_COORDINATE> coordinates; // 4 diffrent coordinates
vector<D3D11_TIL_REGION_SIZE> regions; // 4 as same. but only set the NumTiles=1
vector<UINT> offsets(4, 0);
vector<UINT> rangeFlags(4, 0);
vector<UINT> rangeTileCounts(4, 1);
deviceContext->UpdateTileMappings(myMiscTexture, 4, coordinates.data(),
regions.data(), myMiscBuffer, 4, rangFlags.data(), offsets.data().
rangeTileCounts.data(), D3D11_TILE_MAPPING_NO_OVERWRITE);
map<int, vector<float>> myTileData; // 4 with different data.
for (int index = 0; index < coordinates.size(); index++)
{
D3D11_TILED_RESOURCE_COORDINATE coord = coordinate[index];
D3D11_TILE_REGION_SIZE region = regions[index];
deviceContext->UpdateTiles(myMiscTexture, &coord, &region, myTileData[index].data(), D3D11_TILE_COPY_NO_OVERWRITE);
}
}
i alway got 4 same TileData show in different coordinate.
if i copy the code above with another 4 coordinate like this:
void CalledEveryFrame()
{
UpdateTileMappings(coordinates);
for(coordinates)
{
UpdateTiles(TileData);
}
UpdateTileMappings(coordinates2);
for(coordinates2)
{
UpdateTiles(TileData2);
}
}
i alway got 8 same TileData showing, why?

Related

How to move islands in a highmap

I got a map from Spain that include Canary Island but the islands are so far and the map looks very small, is there any way to move the islands closer to Spain?
Highcharts provide a demo of how to move certain countries. You can use the added functionality provided there to the Point class to move your areas into position. We will utilize the following (slightly modified) code:
// Offset an SVG path by x and y
Highcharts.Point.prototype.offsetPath = function (x, y, redraw, animate) {
var path = this.path || [],
isX = true,
i = 0;
for (; i < path.length; ++i) {
if (Highcharts.isNumber(path[i])) {
path[i] += isX ? x : y;
isX = !isX;
}
}
this.update({
dataLabels: {
x: this.series.xAxis.toPixels(x) - this.series.xAxis.toPixels(0),
y: this.series.yAxis.toPixels(y) - this.series.yAxis.toPixels(0)
},
path: path
}, redraw, animate);
};
To move the points. Then, after loading your map of Spain, you can post-process to move the areas into the desired position. I've made an example here (JSFiddle demo):
Highcharts.mapChart('container', {
// ...
}, function(chart) {
for(let i = 0; i < this.series[0].points.length; i++) {
if(this.series[0].points[i]['hc-key'] == 'es-me') { // Melilla
this.series[0].points[i].offsetPath(0, -900, true, false);
} else if(this.series[0].points[i]['hc-key'] == 'es-gc') { // Las Palmas
this.series[0].points[i].offsetPath(-1200, 0, true, false);
} else if(this.series[0].points[i]['hc-key'] == 'es-tf') { // Tenerife
this.series[0].points[i].offsetPath(-1200, 0, true, false);
} else if(this.series[0].points[i]['hc-key'] == 'es-pm') { // Baleares
this.series[0].points[i].offsetPath(-800, 0, true, false);
}
}
});
This moves Melilla, Las Palmas, Tenerife and Baleares closer by X and Y values provided in the example (1st and 2nd parameter), as well as redrawing (3rd parameter), but not animating (4th parameter).
The normal map of Spain would look like this JSFiddle demo provided by Highcharts.

What is the correct way to add different objects (Parcel) at the same position?

I'm trying to add diferent Parcel objects at the same position. My code looks like this, where Rock extends Parcel:
Point origin = null;
Rock rock = null;
for (int i = 0; i < ROCKS; i++) {
if (i % 10 == 0) {
origin = model.getRandomUnoccupiedPosition(sim.getRandomGenerator());
rock = new Rock(origin, destination);
sim.register(rock);
} else {
Rock r = new Rock(origin, destination);
model.addObjectAtSamePosition(r, rock);
}
}
but after a few iterations, I get this error when trying to pick up the Rock with a Vehicle:
Exception in thread "Thread-1" java.lang.IllegalArgumentException: Parcel must be registered and must be either ANNOUNCED or AVAILABE, it is: null. Parcel: [Parcel-103f852].
at com.google.common.base.Preconditions.checkArgument(Preconditions.java:146)
at com.github.rinde.rinsim.core.model.pdp.DefaultPDPModel.pickup(DefaultPDPModel.java:175)
at me.alexrs.mas.roveragent.RoverAgent.tickImpl(RoverAgent.java:105)
at com.github.rinde.rinsim.core.model.pdp.Vehicle.tick(Vehicle.java:55)
at com.github.rinde.rinsim.core.model.time.TimeModel.tickImpl(TimeModel.java:139)
at com.github.rinde.rinsim.core.model.time.SimulatedTimeModel.doStart(SimulatedTimeModel.java:32)
at com.github.rinde.rinsim.core.model.time.TimeModel.start(TimeModel.java:94)
at com.github.rinde.rinsim.ui.SimulationViewer$5.run(SimulationViewer.java:399)
The only Rock that is registered is the one that has been registered in the Simulator, but if I try to register more than one Rock, I get an exception saying that two objects can't be at the same position.

Updating a point in a line chart when data grouping is in effect

I need to update a specific point in the chart when new data arrives. I've written the following function:
function updatePoint(series, x, y) {
for (i = 0; i < series.data.length - 1; i++) {
var point = series.data[i];
if (point.x === x) {
point.update(y);
return;
}
}
}
This works fine, unless the chart has more than turboThreshold points, in which case the series.data is gone, and I only have series.xData and series.yData to work with. I tried the following variant, but the chart does not actually update:
function updateTurboPoint(series, x, y) {
for (i = 0; i < series.xData.length; i++) {
if (series.xData[i] === x) {
if (series.yData.length > i) {
series.yData[i] = y;
return;
}
}
}
}
Setting a breakpoint on the return, I verified that series.yData[i] has the new value, even though it did not appear on the chart. How can I get this to actually update the chart?
I am using HighStock 2.0.4.
EDIT: Created a JSFiddle: http://jsfiddle.net/swish014/2unh1cLa/
EDIT: Changed the title, as I (now) do not believe turbo mode has anything to do with it.
The two comments were key to figuring out my own problem.
It is related to dataGrouping (and not turbo mode as I first thought).
The series.points array does exist, and updating a point there does update the chart as desired.
In my question, I listed two separate functions to update points, but I believe I can use just one function:
function updatePoint(series, x, y) {
for (i = 0; i < series.points.length - 1; i++) {
var point = series.points[i];
if (point.x === x) {
point.update(y);
return;
}
}
}

my shapes aren't changing colors I'm not sure why

I have a code that draws a bunch of customized shapes from an xml... I want to make each shape select-able /de-selectable by changing the color of the object and changing backk all other colors when things change but my codes broken but i'm not getting any errors or anything it just doesn't work.
var graphicsShape
function drawLayer(layer){
for (var i =0; i < xmlDoc.getElementsByTagName("polygon").length; i++)
{
if (layer == xmlDoc.getElementsByTagName("polygon")[i].childNodes[0].attributes[4].value)
{ drawSegment(i);
}
}
}
// layer = index z
function drawSegment(a){
var vertexList = xmlDoc.getElementsByTagName("polygon")[a].childNodes;
var graphicsObject = new createjs.Graphics();
graphicsShape = new createjs.Shape(graphicsObject);
graphicsObject.setStrokeStyle(1);
graphicsObject.beginStroke(createjs.Graphics.getRGB(0,0,0));
graphicsObject.beginFill(createjs.Graphics.getRGB(255,0,0));
for(var i = 0; i < vertexList.length; i++){
graphicsObject.lineTo(vertexList[i].attributes[2].value, vertexList[i].attributes[3].value)
stage.addChild(graphicsShape);
}
segmentsArray.push(graphicsShape);
//createContainer(segmentsArray[i]);
}
function createArraysForSegments() {
for(var i=0; i <segmentsArray.length; i++){
segmentsData[i] = new Array;
}
}
function ColorChangeAddEventListener() {
for(var i = 0; i < segmentsArray.length; i++){
segmentsArray[i].addEventListener('click', colorChange(i));
}
}
function colorChange(index){
segmentsArray[index].graphics.beginFill('white');
stage.update();
}
i call the functions later
ColorChangeAddEventListener();
drawLayer(0);
stage.update();
if i type segmentsArray[0].alpha =0.5; it works for that shape, but when I put it in segmentsArray[0].addEventsListener('click', function){segmentsArray[0].alpha=0.5;}) that doesn't work
Just setting the beginFill won't affect the current shape, you will also have to segmentsArray[index].graphics.clear() and redraw the shape.
beginFill() is not the setter for a property but rather a command that affects subsequents commands, like drawRect() for example.

Weird lines in Skybox

I have a problem with visible lines appearing at the edges of the Skybox.
http://project-vanquish.co.cc/index.php <-- Shows the problem
Has anyone got any ideas as to why they are appearing? The textures don't have the white edge.
Rendering code block:
public override void Render(GraphicsDevice device)
{
device.DepthStencilState = DepthStencilState.None;
for (int i = 0; i < 6; i++)
{
this.sides[i].Position = CameraManager.ActiveCamera.Position + this.offsets[i];
EffectManager.ActiveShader.SetParameters(this.sides[i]);
foreach (EffectPass pass in EffectManager.ActiveShader.Effect.CurrentTechnique.Passes)
{
pass.Apply();
this.sides[i].Render(device);
}
}
device.DepthStencilState = DepthStencilState.Default;
}
Store your SamplerState:
SamplerState samplerState = device.SamplerStates[0];
Then, set it to AnisotropicClamp (or your preference):
device.SamplerStates[0] = SamplerState.AnisotropicClamp;
then after the render, reset your setting:
device.SamplerStates[0] = samplerState;

Resources