I'm creating a game in (modern) opengl, c++, glm, glfw and openvr.h and currently learning from provided example source code (hellovr_opengl_main.cpp). There are apis found in openvr to provide both the view and projection matrices and used in combination would replicate what your eyes would see in real life through virtual reality goggles.
So I implemented framebuffers into my opengl application and everything worked perfectly so all ok there then followed the examples and tried to access the apis from openvr.h myself, and after that failed i downright copied and pasted from their example code the entire hierarchy of everything that was relevant to this problem and called everything in the same order as they appeared from the example and that didnt work either so ive tried everything i can think of and i cant figure it out
Also i use there matrix definitions as they are until it reaches my code where i convert it to glm::mat4, but i did get the viewmatrix working w/o any modification (like column major)
glm::mat4 CMainApplication::GetCurrentViewProjectionMatrix(vr::Hmd_Eye nEye)
{
Matrix4 i;
if (nEye == vr::Eye_Left)
{
i = m_mat4ProjectionLeft * m_mat4eyePosLeft * m_mat4HMDPose;
}
else if (nEye == vr::Eye_Right)
{
i = m_mat4ProjectionRight * m_mat4eyePosRight * m_mat4HMDPose;
}
Matrix4 i2 = m_mat4eyePosRight * m_mat4HMDPose;//works!
view = glm::mat4(i2[0], i2[1], i2[2], i2[3], i2[4], i2[5], i2[6], i2[7], i2[8], i2[9],
i2[10], i2[11], i2[12], i2[13], i2[14], i2[15]);
Matrix4 i3 = m_mat4ProjectionRight;
project = glm::mat4(i3[0], i3[1], i3[2], i3[3], i3[4], i3[5], i3[6], i3[7], i3[8], i3[9],
i3[10], i3[11], i3[12], i3[13], i3[14], i3[15]);//doesnt work
project = glm::mat4(i3[0], i3[4], i3[8], i3[12], i3[1], i3[5], i3[9], i3[13], i3[2], i3[6],
i3[10], i3[14], i3[3], i3[7], i3[11], i3[15]);//row>>column //doesnt work
return glm::mat4(i[0], i[4], i[8], i[12], i[1], i[5], i[9], i[13], i[2], i[6],
i[10], i[14], i[3], i[7], i[11], i[15]);//doesnt work
return glm::mat4(i[0], i[4], i[8], i[12], i[1], i[5], i[9], i[13], i[2], i[6],
i[10], i[14], i[3], i[7], i[11], i[15]);//row>>column //doesnt work
return glm::mat4(i[12], i[13], i[14], i[15], i[4], i[5], i[6], i[7], i[8], i[9],
i[10], i[11], i[0], i[1], i[2], i[3]);//replace top w/ bottom //doesnt work
}
Related
https://github.com/cocos2d/cocos2d-x/blob/v4/cocos/editor-support/spine/Json.cpp
I need help loading a .txt and pulling out some text using cocos for an old App. Can anyone work up a simple example?
The backstory is that I wrote a working app about 5-6 years ago when cocos used a different json library. They changed the library and I can't decipher the new one enough to get it working again. I am not a programmer, but made the app as a favor for a hospital. The json is used to switch between languages for the script. I don't really even know how to ask a technical question about the library. I know the code is all there, but I don't know how to make it work...
Thanks :)
cocos2dx v4 Json implementation
This is what I figured out eventually. Any improvements you can suggest are welcome.
I use this to read json-response from a translation api:
std::vector<char> * buffer = response->getResponseData();
char * concatenated = (char *) malloc(buffer->size() + 1);
std::string s2(buffer->begin(), buffer->end());
strcpy(concatenated, s2.c_str());
CCLOG ("DEBUG |%s|", concatenated);
Json * json = Json_create(concatenated);
Json *responseData = Json_getItem(json, "responseData");
const char * var22 = Json_getString(responseData, "translatedText", "default");
USED JSON response
{"responseData":
{"translatedText":"ni\u00f1o"}, .....
and copyed the old json.c and json.h in my classes dir.
static void readCurve (Json* frame, spCurveTimeline* timeline, int frameIndex) {
Json* curve = Json_getItem(frame, "curve");
if (!curve) return;
if (curve->type == Json_String && strcmp(curve->valueString, "stepped") == 0)
spCurveTimeline_setStepped(timeline, frameIndex);
else if (curve->type == Json_Array) {
Json* child0 = curve->child;
Json* child1 = child0->next;
Json* child2 = child1->next;
Json* child3 = child2->next;
spCurveTimeline_setCurve(timeline, frameIndex, child0->valueFloat, child1->valueFloat, child2->valueFloat,
child3->valueFloat);
}
}
I used the clibgen.generateLibraryDefinition to generate the Matlab interface for C++ libraries.
I applied it in a Matlab function and it worked well.
However, when I tried to use it in the Matlab Simulink with the Matlab function block, it gave errors " Attempt to extract field 'i' from 'mxArray'. "
Is that anything I'm missing to add in the Simulink?
Thanks!
function cube = fcn(size_x, size_y, range_x_min, range_x_max, ...
range_y_min, range_y_max, power, ...
transmitter_height, receiver_height, ...
transmitter_position, frequency)
coder.extrinsic('clib.Wave.Wave.EMWave');
coder.extrinsic('clib.Wave.Wave.Index');
coder.extrinsic('clib.Wave.Wave.Vec2d');
coder.extrinsic('clib.Wave.Wave.Terrain');
coder.extrinsic('clib.Wave.Wave.Transimtter');
coder.extrinsic('clib.Wave.Wave.Source');
coder.extrinsic('clib.Wave.Wave.Cube');
coder.extrinsic('clib.Wave.Wave.Terrain');
coder.extrinsic('clib.Wave.Wave.Ray');
index = clib.Wave.Wave.Index;
radio_wave = clib.Wave.Wave.EMWave;
terrain = clib.Wave.Wave.Terrain(200,200,range_x_min,range_y_min,range_x_max,range_y_max);
index.i = 1;
index.j = 1;
% radio_wave.transmitter.set_power(1000);
% radio_wave.transmitter.set_height(150.0);
% radio_wave.transmitter.set_number_of_discrete_rays(7200);
%code.varsize('cube',[1 size_x],[1 size_y]);
cube = zeros(200,200);
end
I'm new to the Unreal Engine and C++...
I'm trying to get the assigned Key of an Axis. I found out that the information are stored in the DefaultInput.ini file but how do i access these data programmatically?
There's a GetAxisValue(const FName) method but it does not return anything.
FString AxisName = "MoveForward";
auto value = PlayerInputComponent->GetAxisValue(FName(*AxisName));
What am I doing wrong? I would really appreciate your help.
Im not sure because I use Blueprints most of the time for this, but one way to get the value is to bind it to a method.
(Example of the AFPSCharacter Template)
PlayerInputComponent->BindAxis("MoveForward", this, &APawn::MoveForward);
And later use it in the method
void AFPSCharacter::MoveForward(float Value){
//for example print the val
UE_LOG(LogTemp, Warning, TEXT("%f"), Value);
}
this was my first thought too but unfortunately you can't get the Keys, you just bind the method to an axis name. The MoveForward's "Value" parameter hold the scale value but not the Key value. 1.0f for example when you press "W" or -1.0f when you press "S".
I've already found a solution for my issue. The GetAxisValue(FName) is the wrong method for this purpose.
Instead I found the UInputSettings class that contains a method named GetAxisMappingByName(FName, TArray)
Here a code snippet how it works:
// Get the instance of the InputSettings
UInputSettings* InputSettings = UInputSettings::GetInputSettings();
// AxisMappings with all the information will be stored here
TArray<FInputAxisKeyMapping> VerticalKeys;
TArray<FInputAxisKeyMapping> HorizontalKeys;
// Load the AxisMappings
InputSettings->GetAxisMappingByName(FName("MoveForward"), VerticalKeys);
InputSettings->GetAxisMappingByName(FName("MoveRight"), HorizontalKeys);
// Each MovementKey gets its own variable
FKey ForwardKey;
FKey BackKey;
FKey LeftKey;
FKey RightKey;
// Assign each key to the correct direction
for (FInputAxisKeyMapping verticalKey : VerticalKeys)
{
if (verticalKey.Scale == 1.0f)
ForwardKey = verticalKey.Key;
else if (verticalKey.Scale == -1.0f)
BackKey = verticalKey.Key;
}
for (FInputAxisKeyMapping horizontalKey : HorizontalKeys)
{
if (horizontalKey.Scale == 1.0f)
RightKey = horizontalKey.Key;
else if (horizontalKey.Scale == -1.0f)
LeftKey = horizontalKey.Key;
}
Is there a better solution for assigning the keys than using for loops? Feel free to correct my code since I'm not really an expert in C++. ;-)
I know it is a stupid question, but when changing visual libraries I found a "throuble" with FMX...
My problem is: I need to do my own border, so I set the propriety to Border Style:"None", but the application runs in full screen, also covering the windows toolbar, so I would like a way to resize the application form according to the screen eg.:
mainForm->Height = Screen->Height - 10;
It is possible using VCL, but are there any way to do it using FMX library?
The maximum I conquested with FMX is (I don't know how does it returns values, and the kind of values):
Screen->Size(); // TSize
I've also conquested it now, but I have compiler error:
TSize* Tamanho = new TSize;
Tamanho = Screen->Size();
frmPrincipal->Width = Tamanho->Width;
frmPrincipal->Height = Tamanho->Height - 10;
Error:"E2034 Cannot covert 'TSize' to 'TSize*'"
Finally I've tried to put it on frmPrincipal.h, but the same error:
TSize *Tamanho;
PS.: Other possible solutions to solve the "main problem" are acceptable...
Thanks a LOT!
TScreen::Size() return an actual instance of the TSize struct, not a TSize* pointer. You need to change your code accordingly:
TSize Tamanho = Screen->Size();
frmPrincipal->Width = Tamanho.Width;
frmPrincipal->Height = Tamanho.Height - 10;
Alternatively, you can use FMX's Platform Services framework to access the IFMXScreenService interface directly (this is what TScreen::Size() uses internally):
_di_IInterface Intf;
if (TPlatformServices::Current->SupportsPlatformService(__uuidof(IFMXScreenService), Intf))
{
_di_IFMXScreenService Svc = Intf;
TPoint size = Svc->GetScreenSize().Round();
frmPrincipal->Width = size.X;
frmPrincipal->Height = size.Y - 10;
}
Ok I have written some basic generic webservices before but I have never tried to consume a 3rd party one.
The one I am trying to consume is
http://opendap.co-ops.nos.noaa.gov/axis/webservices/predictions/wsdl/Predictions.wsdl
I am not getting any results back from this what so ever and cannot figure out why.
More odd is it is not even reaching PredictionsClient_getPredictionsAndMetadataCompleted when I put a break point in the code it doesn't even reach it.
Any suggestions would be greatly appreciated
public void Bouy(double meters)
{
PredictionService.Parameters PredictionParams = new PredictionService.Parameters();
PredictionService.PredictionsPortTypeClient PredictionsClient = new PredictionService.PredictionsPortTypeClient();
GeoCoordinateWatcher gc = new GeoCoordinateWatcher(GeoPositionAccuracy.Default);
//gc.Position.Location.Latitude, gc.Position.Location.Longitude
GeoCoordinate myLocation = new GeoCoordinate(27.931631,-82.802582);
foreach (var bl in BouyLocation.GetAll())
{
GeoCoordinate otherLocation = new GeoCoordinate(bl.Lat, bl.Lon);
PredictionParams.beginDate = DateTime.Now.ToString("yyyyMMdd");
PredictionParams.endDate = DateTime.Now.AddDays(1.0).ToString("yyyyMMdd");
PredictionParams.stationId = bl.LocationID;
PredictionParams.timeZone = 0;
PredictionParams.unit = 1;
PredictionParams.dataInterval = 6;
PredictionsClient.getPredictionsAndMetadataCompleted += new EventHandler<PredictionService.getPredictionsAndMetadataCompletedEventArgs>(PredictionsClient_getPredictionsAndMetadataCompleted);
PredictionsClient.getPredictionsAndMetadataAsync(PredictionParams);
double mymeters = myLocation.GetDistanceTo(otherLocation);
if (mymeters < meters)
{
TextBlock DynTextBlock = new TextBlock
{
Name = "Appearance" + bl.LocationID,
Text = bl.LocationName + PredictionResult,
TextWrapping = System.Windows.TextWrapping.Wrap,
Margin = new Thickness(12, -6, 12, 0),
Style = (Style)Resources["PhoneTextSubtleStyle"]
};
DynamicAppearance.Children.Add(DynTextBlock);
this.nearByLocations.Add(new BouyLocationModel() { LocationName = bl.LocationName, LocationID = bl.LocationID, Lat = bl.Lat, Lon = bl.Lon });
}
}
var test = nearByLocations;
}
void PredictionsClient_getPredictionsAndMetadataCompleted(object sender, PredictionService.getPredictionsAndMetadataCompletedEventArgs e)
{
string err = e.Error.ToString();
PredictionResult = e.Result.ToString();
}
Loooking at the code you have here I think that you have used the importing of a ServiceReference to auto build the classes for you?
Unfortunately I have found that this is rather temperamental on WP7 and the only way I actually got it to work was when I connected it to a Microsoft WCF service. Connecting to anything else just doesn't work.
If you do google searches there are various pages talking about the fact it doesn't work and ways around it (which I couldn't get to work).
However, there are ways around it but it isn't as simple as the auto-generated stuff. Basically you do things manually.
Although there are other ways to manually create the web service what I did was follow the information in the following which worked well: http://zetitle.wordpress.com/2010/10/14/using-reactive-extensions-with-webrequest/
You will need to parse the response yourself but XML to LINQ works really well for this.
Hope that helps, or maybe someone will have the solution as it is something I am interested in knowing how to get working too