How to make a rotating cube move horizontally? - c++

I used C++/OpenGL and drew a rotating cube. Now I want to make it move horizontally while it is rotating. I put a line glTranslatef(0.01, 0, 0). It moves horizontally but does not rotate. Following is my code. Any idea how to fix it so that the cube can move horizontally across while it is rotating?
void drawcube(void) {
int p[][3] = { { 1, 1, 1 }, { 1, -1, 1 }, { -1, -1, 1 }, { -1, 1, 1 },
{ 1, 1, -1 }, { 1, -1, -1 }, { -1, -1, -1 }, { -1, 1, -1 } };
int e[][4] = { { 0, 3, 2, 1 }, { 3, 7, 6, 2 }, { 7, 4, 5, 6 }, { 4, 0, 1, 5 },
{ 0, 4, 7, 3 }, { 1, 2, 6, 5 } };
float c[][3] = { { 1.0, 0, 0 }, { 0, 1.0, 0 }, { 1.0, 1.0, 0.0 },{ 0, 0, 1.0 }, { .6, 0, .6 }, { 0, .6, .6 } };
int i;
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glTranslatef(0.01, 0, 0);
glRotatef(global.angle, 1.0, 1.0, 1.0);
for (i = 0; i < 6; ++i) {
glColor3fv(c[i]);
glBegin(GL_QUADS);
glVertex3iv(p[e[i][0]]);
glVertex3iv(p[e[i][1]]);
glVertex3iv(p[e[i][2]]);
glVertex3iv(p[e[i][3]]);
glEnd();
}
glutSwapBuffers();
}

Related

Questions about HLSL Semantics

I want to define the vertex struct like this:
struct VertexIn
{
float3 PosL : POSITION;
float3 NormalL : NORMAL;
float2 TexC : TEXCOORD;
float SH[9]; // ?
};
How to choose the vertex semantics of the 'SH' array? Can i define a semantic by myself?
Then I tried this:
// in hlsl:
struct VertexIn
{
float3 PosL : POSITION;
float3 NormalL : NORMAL;
float2 TexC : TEXCOORD;
float SH[9] : SHCOEFFICIENT; // ???
};
// cpp:
mInputLayout =
{
{ "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D12_INPUT_CLASSIFICATION_PER_VERTEX_DATA, 0 },
{ "NORMAL", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 12, D3D12_INPUT_CLASSIFICATION_PER_VERTEX_DATA, 0 },
{ "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 24, D3D12_INPUT_CLASSIFICATION_PER_VERTEX_DATA, 0 },
{ "SHCOEFFICIENT", 0, DXGI_FORMAT_R32_FLOAT, 0, 32, D3D12_INPUT_CLASSIFICATION_PER_VERTEX_DATA, 0}, // ???
};
Of course, it's wrong.
So I split the array into 9 elements temporarily, but it looks stupid.
You can use SemanticIndex parameter. You could define your input layout
mInputLayout =
{
{ "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D12_INPUT_CLASSIFICATION_PER_VERTEX_DATA, 0 },
{ "NORMAL", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 12, D3D12_INPUT_CLASSIFICATION_PER_VERTEX_DATA, 0 },
{ "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 24, D3D12_INPUT_CLASSIFICATION_PER_VERTEX_DATA, 0 },
{ "SHCOEFFICIENT", 0, DXGI_FORMAT_R32_FLOAT, 0, 32, D3D12_INPUT_CLASSIFICATION_PER_VERTEX_DATA, 0},
{ "SHCOEFFICIENT", 1, DXGI_FORMAT_R32_FLOAT, 0, 36, D3D12_INPUT_CLASSIFICATION_PER_VERTEX_DATA, 0},
{ "SHCOEFFICIENT", 2, DXGI_FORMAT_R32_FLOAT, 0, 40, D3D12_INPUT_CLASSIFICATION_PER_VERTEX_DATA, 0},
...
{ "SHCOEFFICIENT", 8, DXGI_FORMAT_R32_FLOAT, 0, 64, D3D12_INPUT_CLASSIFICATION_PER_VERTEX_DATA, 0}
};
Or like this:
mInputLayout =
{
{ "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D12_INPUT_CLASSIFICATION_PER_VERTEX_DATA, 0 },
{ "NORMAL", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 12, D3D12_INPUT_CLASSIFICATION_PER_VERTEX_DATA, 0 },
{ "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 24, D3D12_INPUT_CLASSIFICATION_PER_VERTEX_DATA, 0 },
{ "SHCOEFFICIENT", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 32, D3D12_INPUT_CLASSIFICATION_PER_VERTEX_DATA, 0},
{ "SHCOEFFICIENT", 1, DXGI_FORMAT_R32G32B32_FLOAT, 0, 44, D3D12_INPUT_CLASSIFICATION_PER_VERTEX_DATA, 0},
{ "SHCOEFFICIENT", 2, DXGI_FORMAT_R32G32B32_FLOAT, 0, 56, D3D12_INPUT_CLASSIFICATION_PER_VERTEX_DATA, 0},
};
but change your vertex
struct VertexIn
{
float3 PosL : POSITION;
float3 NormalL : NORMAL;
float2 TexC : TEXCOORD;
float3 SH[3] : SHCOEFFICIENT;
};

Chartjs not displaying data from a dynamic stored variable

I am having issue in representing two datasets on my chartjs chart when both of my data is from a stored variable. When both of my data {inbound & outbound} is from a stored(and unique) variable, It shows two line graph but having similar data with the inbound data list inheriting the outbound data list. The inbound and outbound data list are two separate data and should be shown as two unique datasets on the chart.
My code is this
var inbound = InboundSmsCountList;
var outbound = OutboundSmsCountList;
var ff = MonthDaysList;
var combined_arraysx = [InboundSmsCountList,OutboundSmsCountList];
var max2 = combined_arraysx.reduce(function(final, current) {
for (var i = 0; i < final.length; ++i) {
if (current[i] > final[i]) {
final[i] = current[i];
}
}
return final;
});
var maxValue = Math.max.apply(Math, max2);
console.log(maxValue);
var ctx6 = document.getElementById('chartBar6').getContext('2d');
var gradient1x = ctx6.createLinearGradient(0, 350, 0, 0);
gradient1x.addColorStop(0, 'rgba(241, 0, 117,0)');
gradient1x.addColorStop(1, 'rgba(241, 0, 567,.5)');
var gradient2x = ctx6.createLinearGradient(0, 280, 0, 0);
gradient2x.addColorStop(0, 'rgba(86, 87, 255,0)');
gradient2x.addColorStop(1, 'rgba(34, 45, 255,.5)');
var config = {
type: 'line',
data: {
labels: ff,//['May-01', 'May-02', 'May-03', 'May-04', 'May-05', 'May-06', 'May-07', 'May-08', 'May-09', 'May-10', 'May-11', 'May-12', 'May-13', 'May-14', 'May-15', 'May-16', 'May-17', 'May-18', 'May-19', 'May-20', 'May-21', 'May-22', 'May-23', 'May-24', 'May-25', 'May-26', 'May-27', 'May-28', 'May-29', 'May-30', 'May-31'],
datasets: [{
label: 'Outbound',
data: outbound,//[1, 2, 0, 0, 84, 0, 10, 16, 8, 0, 0, 0, 4, 4, 1, 0, 0, 0, 1, 5, 0, 1, 0, 0, 0, 0, 71, 0, 0, 0, 0],
borderColor: '#00cccc',
borderWidth: 1,
backgroundColor: gradient2x,
},{
label: 'Inbound',
data: inbound,//[0, 0, 0, 0, 5, 0, 0, 0, 6, 0, 0, 0, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 0, 0, 0, 0],
borderColor: '#00cccc',
borderWidth: 1,
backgroundColor: gradient1x,
}]
},
options: {
maintainAspectRatio: false,
legend: {
display: true,
position:"top",
labels: {
display: true
}
},
scales: {
xAxes: [{
//stacked: true,
barPercentage: 0.5,
ticks: {
beginAtZero:true,
fontSize: 11
},
gridLines: {
display: false,
drawBorder: true
},
}],
yAxes: [{
//stacked: true,
ticks: {
fontSize: 10,
color: '#97a3b9',
min: 0,
max: maxValue
},
gridLines: {
display: false,
drawBorder: true
},
}]
}
}
};
new Chart(ctx6, config );
when both data is from stored variable - see image
data: {
labels: ff,//['May-01', 'May-02', 'May-03', 'May-04', 'May-05', 'May-06', 'May-07', 'May-08', 'May-09', 'May-10', 'May-11', 'May-12', 'May-13', 'May-14', 'May-15', 'May-16', 'May-17', 'May-18', 'May-19', 'May-20', 'May-21', 'May-22', 'May-23', 'May-24', 'May-25', 'May-26', 'May-27', 'May-28', 'May-29', 'May-30', 'May-31'],
datasets: [{
label: 'Outbound',
data: outbound,
borderColor: '#00cccc',
borderWidth: 1,
backgroundColor: gradient2x,
},{
label: 'Inbound',
data: inbound,
borderColor: '#00cccc',
borderWidth: 1,
backgroundColor: gradient1x,
}]
}
when outbound data is a stored variable while the inbound data is raw list/array it shows correct graph-two separate datasets - see image
data: {
labels: ff,//['May-01', 'May-02', 'May-03', 'May-04', 'May-05', 'May-06', 'May-07', 'May-08', 'May-09', 'May-10', 'May-11', 'May-12', 'May-13', 'May-14', 'May-15', 'May-16', 'May-17', 'May-18', 'May-19', 'May-20', 'May-21', 'May-22', 'May-23', 'May-24', 'May-25', 'May-26', 'May-27', 'May-28', 'May-29', 'May-30', 'May-31'],
datasets: [{
label: 'Outbound',
data: outbound,
borderColor: '#00cccc',
borderWidth: 1,
backgroundColor: gradient2x,
},{
label: 'Inbound',
data: [0, 0, 0, 0, 5, 0, 0, 0, 6, 0, 0, 0, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 0, 0, 0, 0],
borderColor: '#00cccc',
borderWidth: 1,
backgroundColor: gradient1x,
}]
}
Can someone advise how to fix this?
Thank you.

Initialization of a struct array [duplicate]

This question already has answers here:
How to initialize an array of struct in C++?
(3 answers)
Closed 5 years ago.
struct Sensors
{
int pin;
int angle;
bool state;
};
Sensors sensor[6];
How can I initialize every field of sensor like a normal array?
This method
mydata data[] = { { 1, 2, 3, 4, 5, 6 },
{ 0, 60, 120, 180, -120, -60 },
{ false, false, false, false, false, false} };
doesn't work, it returns me too many initialization.
You can use aggregate initialization.
struct Sensors
{
int pin;
int angle;
bool state;
};
Sensors sensor[6] = {
{ 0, 0, true },
{ 1, 0, true },
{ 2, 0, false },
{ 3, 0, false },
{ 4, 0, false },
{ 5, 0, false }
};
struct Sensors
{
int pin;
int angle;
bool state;
};
int main()
{
Sensors sensor[6] = {
{ 1, 2, false },
{ 1, 2, true },
{ 1, 3, false },
{ 2, 2, false },
{ -1, -2, true },
{ 1, 2, false }
};
return 0;
}

chart js (version 2) bar chart superimpose one data set onto another

I have a horizontal bar chart with two datasets
I am trying to superimpose the blue bars onto red.so that the intesection can be a start time and the bar can indicate a range.
is there any way to do this?
data: {
labels: ["C#", "ASP.NET MVC", "WebAPI", "SQL", "Entity Framework","NServiceBus / MSMQ", "WCF", "WPF / XAML", "",
"HTML / CSS", "JavaScript", "Angular JS v1","",
"DI / IoC", "TDD / Unit Testing", "UI Testing (Seleno)", "CI (Teamcity)"],
datasets: [
{
label:"# years",
data: [3, 2, 1, 4, 6, 2, 0.5, 0.25, 0,
7, 2, 0.5, 0,
2, 2, 0.5, 0.5],
backgroundColor: 'red',
borderWidth: 0
},
{
label:"# years",
data: [6, 4, 3, 6, 6, 2, 0.5, 0.25, 0,
7, 2, 0.5, 0,
2, 2, 0.5, 0.5],
backgroundColor: 'blue',
borderWidth: 0
}
]
}
options:{
scales: {
xAxes: [{ stacked:true}]
}
}

Retrieving an array from a multi-dimensional array

I'm working on some mathematics research, and I'm having difficulty working my way through the c++ language. Specifically, (and i'm not sure if this is even possible) I'd like to retrieve an array from a multi-dimensional array. Let me clarify. As I understand it, a multi-dimensional array is an array of arrays. I am working with a 3-D array, and what I want to do is retrieve an entire 2-D array from that 3-D array. Here is a snippet from my code. The first declarations are how I had it before (with 15 2-D arrays), the next declaration is how I want things to go (so that I can use a while loop to move through all my 2-D arrays checking for things as it goes).
int round1[3][2] = { { 1, 2 }, { 3, 4 }, { 5, 6 } };
int round2[3][2] = { { 1, 2 }, { 3, 5 }, { 4, 6 } };
int round3[3][2] = { { 1, 2 }, { 3, 6 }, { 4, 5 } };
int round4[3][2] = { { 1, 3 }, { 2, 4 }, { 5, 6 } };
int round5[3][2] = { { 1, 3 }, { 2, 5 }, { 4, 6 } };
int round6[3][2] = { { 1, 3 }, { 2, 6 }, { 4, 5 } };
int round7[3][2] = { { 1, 4 }, { 2, 3 }, { 5, 6 } };
int round8[3][2] = { { 1, 4 }, { 2, 5 }, { 3, 6 } };
int round9[3][2] = { { 1, 4 }, { 2, 6 }, { 3, 5 } };
int round10[3][2] = { { 1, 5 }, { 2, 3 }, { 4, 6 } };
int round11[3][2] = { { 1, 5 }, { 2, 4 }, { 3, 6 } };
int round12[3][2] = { { 1, 5 }, { 2, 6 }, { 3, 4 } };
int round13[3][2] = { { 1, 6 }, { 2, 3 }, { 4, 5 } };
int round14[3][2] = { { 1, 6 }, { 2, 4 }, { 3, 5 } };
int round15[3][2] = { { 1, 6 }, { 2, 5 }, { 3, 4 } };
int rounds[15][3][2] = { { { 1, 2 }, { 3, 4 }, { 5, 6 } }, { { 1, 2 }, { 3, 5 }, { 4, 6 } }, { { 1, 2 }, { 3, 6 }, { 4, 5 } }, { { 1, 3 }, { 2, 4 }, { 5, 6 } }, { { 1, 3 }, { 2, 5 }, { 4, 6 } }, { { 1, 3 }, { 2, 6 }, { 4, 5 } }, { { 1, 4 }, { 2, 3 }, { 5, 6 } }, { { 1, 4 }, { 2, 5 }, { 3, 6 } }, { { 1, 4 }, { 2, 6 }, { 3, 5 } }, { { 1, 5 }, { 2, 3 }, { 4, 6 } }, { { 1, 5 }, { 2, 4 }, { 3, 6 } }, { { 1, 5 }, { 2, 6 }, { 3, 4 } }, { { 1, 6 }, { 2, 3 }, { 4, 5 } }, { { 1, 6 }, { 2, 4 }, { 3, 5 } }, { { 1, 6 }, { 2, 5 }, { 3, 4 } } };
int tourney_count = 0;
string tourney[5] = { "", "", "", "", "" };
int roundcount_a = 0;
int roundcount_b = 0;
int roundcount_c = 0;
int roundcount_d = 0;
int roundcount_e = 0;
if (is_compatible(rounds[0][][], rounds[3][][]))
//do stuff
return 0;
is_compatible is a function I've defined above that basically checks to see if any two 2-D arrays contain like pairs. My plan is to do some work with while loops (haven't quite figured it all out yet) to go through my 3-D array and move from one to the next checking to see which ones are compatible, and then moving on to a third array. That's about it.
If anyone has any better ideas on how to go about something like this (not using arrays in arrays in arrays), then I would be happy to hear you out. However, I'd really just like to know if I can do what i'm trying to do and return one of these 2-D arrays from a 3-D array.
Thanks.