Last vertex in vertex buffer not being set - graphics

I'm attempting to render a sphere in Direct11 using SharpDX. I have correctly read in the OBJ model, created the vertex buffers, and set the buffers on the context for rendering.
My problem is that everything rendering perfectly EXCEPT the very last vertex, which is rendered as if it were at 0, 0, 0. Below is a screen shot of this:
I have checked the vectors that get used when creating the buffers and there is no missing data in there, I even changed the last element in the array like this:
vertexBufferArray[vertexBufferArray.Length - 1].X = 1.0f;
and had no result. Whereas if I change the second to last element like this:
vertexBufferArray[vertexBufferArray.Length - 2].X = 1.0f;
I get this result:
The vertex count that I am passing to the render call is correct because if I pass it VertexCount - 1, I don't get the last triangle at all, and if I pass it VertexCount + 100, nothing changes at all.
Any ideas?

As usual I end up fixing the problem 10 mins after I make a big post about it.
The problem was my Input Assembler, my input elements for POSITION and NORMAL were of Format.R32G32B32A32_Float, when they should have been Format.R32G32B32_Float since I was giving my vertices in as Vector3s.

Related

Changes in a temporary variable are affecting the variable that feeds from

I'm designing a Mastermind game, which basically compares 2 lists and marks the similarities. When a colour is found at the right place, a flag making the correct position is added and the item found on the reference list is marked off. The reference list is feeding off an array from another function. The problem is at the mark off, as any changes done to the reference list is changing also the original array, which i don't want it to happen
tempCode = mCode #mCode is the array combination randomly generated from another function
for i in range (len(uCode)): #user input array
for j in range (len(tempCode)): #temp array
if uCode[i] == tempCode[j]: # compare individual chars
if i == j: #compare position
flagMark = "*"
tempCode.insert(j+1, "x") #problem starts here
tempCode.remove(tempCode[j])
fCode.append(flagMark)
When the insert is reached both the tempCode and mCode change which it is not intended.
The code is written in a way should the user enter a combination of the same colours, thus checking the chras(the colours are just letters) and the position, and then mark them of with "x"
As it stands, when it gets to
tempCode.insert(j+1, "x")
the arrays will change to
mCode = ["B","R","x","G","Y"]
tempCode = ["B","R","x","G","Y"]
when I would just want
mCode = ["B","R","G","Y"]
tempCode = ["B","R","x","G","Y"]
See also this answer, which is a different presentation of the same problem.
Essentially, when you do tempCode = mCode, you're not making a copy of mCode, you're actually making another reference to it. Anything you do to tempCode thereafter affects the original as well, so at any given time the condition tempCode == mCode will be true (as they're the same object).
You probably want to make a copy of mCode, which could be done in either of the following ways:
tempCode = mCode.copy()
tempCode = mCode[:]
which produces a different list with the same elements, rather than the same list

code produces a 2d histogram but the results dont match with hist2d

I am trying to write a histogram builder to construct a 2d histogram for my assignment work. This is [my code][1]:
def Build2DHistogramClassifier(X1,X2,T,B,x1min,x1max,x2min,x2max):
HF=np.zeros((B,B),dtype='int');#initialising a empty array of integer type
HM=np.zeros((B,B),dtype='int');
bin_row_indices=(np.round(((B-1)*(X1-x1min)/(x1max-x1min)))).astype('int32');"""this logic decides which bin the value goes into"""
bin_column_indices=(np.round(((B-1)*(X2-x2min)/(x2max-x2min)))).astype('int32');"""np.round-->applies the formula to all the values in the array"""
for i,(r,c) in enumerate(zip(bin_row_indices, bin_column_indices)):
"""enumerate-->if we put array or list into it gives output with index/count i """
if T[i]=='Female':
HF[r,c]+=1;
else:
HM[r,c]+=1;
return [HF, HM]
but the problem is that the results( count in each bin) i am getting is not matching the what i get from using hist2d function in numpy( i passed the same bin size)
i am sorry if my code is not in the right format. Please click on the hyperlink to a gist i created with the same code.
what is the mistake in my code?
how do i correct it?
thanks
By rounding when assigning to bins you are treating the bins as bin centers. The numpy convention is to use them as bin edges.
Remove the two calls to round() from your code and change B-1 to B. You should now get the same results with your function and with np.histogram2d.

Why doesn't my RangeEditor work, when I use mode='spinner'?

In a HasTraits subclass, I have the following Trait defined:
tx_lane_sel = Range(0, 12)
If I display it in my View, using:
Item('tx_lane_sel')
it works as expected, displaying a slider bar, which ranges from 0 to 12.
However, if I try to display it, using:
Item('tx_lane_sel', editor=RangeEditor(mode='spinner'))
the resultant spinner only offers me choices '0' and '1'!
How do I get the spinner working correctly? That is, how do I get it to offer me the full range [0, 12]?
The RangeEditor is not especially ment for Range traits. Thus, as for integers or floats, you need to specify the range by using the low=0, high=12 or the low_name or high_name editor factory attributes:
Item("tx_lane_sel", editor=RangeEditor(low=0, high=12, mode='spinner'))

Why Text cursor coordinates are not updated correctly?

To create a simple line-column counter for my text editor, I decided to simply use the index function of the tkinter.Text widget. In fact, the index function returns a string representing the line and column of the coordinates passed as argument to it.
Specifically, I am using cursor_pos = text.index(tkinter.INSERT) to get the index of the cursor, since, from the effbot website on tkinter.INSERT:
tkinter.INSERT corresponds to the insertion cursor.
The problem is that tkinter.INSERT seems to give me the last cursor position until I move the cursor with the arrows (for example).
This is the function that handles the count of the lines and columns:
def on_key_pressed(self, event=None):
"""Docs """
if self.tpane is not None:
print(self.lines, self.columns)
self.tpane.update()
cursor_pos = self.tpane._tabs[self.tpane.selected()].text.index(tkinter.INSERT)
self.lines = int(cursor_pos.split('.')[0])
self.columns = int(cursor_pos.split('.')[1])
print(self.lines, self.columns)
self.line_c.config(text='Lines: ' + str(self.lines))
self.col_c.config(text='Columns: ' + str(self.columns))
self.update()
I don't know if you can understand the situation... When I first type a letter on the editor, the self.columns variable does not update to 1 (remains 0) until I write the second letter, where it updates to 1, and so on. But there's a trick to make it update without writing a new letter. Once written the first letter, if I move the cursor with the arrows, it updates the self.columns to actually 1.
Another problem is when I try to delete a existent character. For example, if I have 3 characters (and suppose I have self.columns to 3), and I press delete, self.columns update inexplicably to 4, and if I try to remove another character, at this point, it updates to 3.
This problems exists also for the self.lines in the on_key_pressed event handler. I am not sure if this is supposed to happen, and if yes, then I am missing something...
This happens because your custom binding fire before the built-in bindings, and it is the built-in bindings that actually modify the widget and change the cursor position.
You can change the order by leveraging bindtags. For more information see this question: Basic query regarding bindtags in tkinter
For an example of how to change the bindtags, see this answer: https://stackoverflow.com/a/3513906/7432
If you don't want to deal with bindtags, you can bind to <KeyRelease>. Built-in bindings happen on a key press, so the release binding will always fire after the widget has been updated.

Why am I getting an array of NANs when trying to plot a map with D3.js?

I am tring to plot a map with d3.js using GeoJSON, but the paths generated look like this:
<path d="MNaN,NaNLNaN,NaNLNaN,NaNLNaN,NaNLNaN,NaNLNaN,NaNLNaN,NaNLNaN,NaNLNaN,NaNLNaN,‌​NaNLNaN,NaNLNaN,NaNLNaN,NaNLNaN,NaNLNaN,NaNLNaN,NaNLNaN,NaNLNaN,NaNLNaN,NaNLNaN,N‌​aNLNaN,NaNLNaN,NaNLNaN,NaNLNaN,NaNLNaN,NaNLNaN,NaNLNaN,NaNLNaN,NaNLNaN,NaNLNaN,Na‌​NLNaN,NaNLNaN,NaNLNaN,NaNLNaN,NaNLNaN,NaNLNaN,NaNLNaN,NaNLNaN,NaNLNaN,NaNLNaN,NaN‌​LNaN,NaNLNaN,NaNLNaN,NaNLNaN,NaNLNaN,NaNLNaN,NaNLNaN,NaNLNaN,NaNLNaN,NaNLNaN,NaNL‌​NaN,NaNLNaN,NaNLNaN,NaNLNaN,NaNLNaN,NaNLNaN,NaNLNaN,NaNLNaN,NaNLNaN,NaNLNaN,NaNLN‌​aN,NaNLNaN,NaNLNaN,NaNLNaN,NaNLNaN,NaNLNaN,NaNZ">
the code and data are in this Gist:
https://gist.github.com/4157853
I can load the data just fine on QGIS.
Does any one know what is causing this?
The way you have specified the offset in the Mercator projection doesn't seem right. The projection.translate method expects a two element array:
https://github.com/mbostock/d3/wiki/Geo-Projections#wiki-mercator_translate
So instead of:
proj.translate(-43.8,-23.2).scale(10);
you would need to say:
proj.translate([-43.8,-23.2]).scale(10);
-- edit --
See source of projection.translate: https://github.com/mbostock/d3/blob/3.0/src/geo/projection.js#L139
projection.translate = function(_) {
if (!arguments.length) return [x, y];
x = +_[0];
y = +_[1];
return reset();
};
If the argument _ is not an array then +_[0] will return a NaN and therefore the x and y will become NaNs. (This is because trying to get one element from a number (e.g. 213[0]) returns undefined and casting undefined to a number (e.g. +undefined) yields NaN.)
If the code you posted in the gist is everything you're trying to run, then the data you show in data.json is not being loaded anywhere. Anyway, your draw function is acting on the data defined by the variable map (line 16), which refers to a simulation variable which isn't set anywhere. And even if it did, line 34 then refers to a features property of the object passed in as json, which map does not have.
In summary, you need to pass the JSON you posted in the gist to your draw function. Then it might well work. If you don't pass in valid data to the d3 SVG helpers, you'll get a bunch of NaN out.

Resources