Detecting orientation of iPhone using C++ - c++

Embarcadero C++Builder 10.3.2 Enterprise
Searching the internet, I could not find any FMX code for this. Based on Delphi code, this should have worked but the compiler does not like it
if (Application->FormFactor->Orientations == Fmx::Types::TScreenOrientations::Landscape) {
//Landscape
}
Also, the value of Application->FormFactor->Orientations is the same whatever the orientation of the iphone. {System::SetBase = {Data = {[0] = 11 '\v'}}}
How does one determine the orientation?

The Orientations property is a TFormOrientations, which is a System::Set of TFormOrientation values. You can't use Set::operator== to compare it to a single value, which is why you are getting a compiler error. However, you can use the Set::Contains() method to check if it has a given value, eg:
if (Application->FormFactor->Orientations.Contains(Fmx::Forms::TFormOrientation::Landscape)) {
//...
}
In any case, the Orientations property specifies which orientation(s) the application's Forms are allowed to take (a value of 11 has its 1st, 2nd, and 4th bits set to 1, which correspond to the Portrait, Landscape, and InvertedLandscape orientations being enabled). It does not report what the device's current orientation is. For that, use the IFMXScreenService::GetScreenOrientation() method instead, eg:
_di_IFMXScreenService ScreenService;
if (TPlatformServices::Current->SupportsPlatformService(__uuidof(IFMXScreenService), &ScreenService)) {
if (ScreenService->GetScreenOrientation() == Fmx::Types::TScreenOrientation::Landscape) {
//...
}
}

Related

How can I implement a decay for a matrix transformation with react-native-gesture-handler and reanimated?

I'm trying to learn react-native-gesture-handler and react-native-reanimate. I like the idéa of using matrices for transformation, but I have a hard time understanding where to fit in physics functions, such as withDecay.
I want to use the new Gestures API (https://docs.swmansion.com/react-native-gesture-handler/docs/api/gestures/gesture) instead of the old gestureHandler API (https://docs.swmansion.com/react-native-gesture-handler/docs/gesture-handlers/api/common-gh)
Here is a nice example of using matrices for transformation and simply multiplying the change-matrice with the current matrice.
https://github.com/wcandillon/can-it-be-done-in-react-native/blob/master/bonuses/sticker-app/src/GestureHandler.tsx
This concept works great, but I also want to have a decay effect after ending a pan, i.e. the translation should continue to glide a bit.
Here is my first attempt. It does not work, and might be a bit naive. But I think that the code shows what I want to do. I just don't know how to do it correctly. My attempt was to add the .onEnd event, compared to Williams Candillon's original code.
const pan = Gesture.Pan()
.onChange(e => {
matrix.value = multiply4(
Matrix4.translate(e.changeX, e.changeY, 0),
matrix.value,
);
})
.onEnd(({velocityX, velocityY}) => {
matrix.value = multiply4(
Matrix4.translate(
withDecay({velocity: velocityX}),
withDecay({velocity: velocityY}),
0,
),
matrix.value,
);
});
the problem here is the withDecay returns an animation value (it auto update). So the idea would be to do trX.value = withDecay(), same of y and then use useDerivedValue to get the total Matrix4. I hope this helps.

Landscape Creation C++ UE4.27

I would like to create a landscape from scratch in unreal engine 4.27 using C++ only. I have only a simple notion of the process, which revolves around GetWorld()->SpawnActor<ALandscape>, ALandscapeProxy::Import(...) and importing a height/weight map.
I used the LandscapeEditorDetailCustomization_NewLandscape::OnCreateButtonClicked() method as a learning ground, but unfortunately I am at an impasse.
From what I have gathered from my searches there not a lot of examples on the matter. Does anyone have a suggestion or an example?
This is the solution I came up with, with many thanks to ChenHP (or chpsemail) who gave me a solution to this. Firstly, declare the following variables. A better understanding can be found here.
FQuat InRotation
FVector InTranslation
FVector InScale
FTransform LandscapeTransform{InRotation, InTranslation, InScale}
int32 QuadsPerSection
int32 SectionsPerComponent
int32 ComponentCountX
int32 ComponentCountY
int32 QuadsPerComponent
int32 SizeX
int32 SizeY
Create containers for the heights and materials of the landscape:
TArray<FLandscapeImportLayerInfo> MaterialImportLayers
TMap<FGuid, TArray<uint16>> HeightDataPerLayers
TMap<FGuid, TArray<FLandscapeImportLayerInfo>> MaterialLayerDataPerLayers
It is important to note that heights in UE4 are of uint16 type, with 0 the deepest and 65'534 the highest. So for a flat map all height entries should be 32768.
The number of heights is the resolution of the map which is dependent on SizeX and SizeY.
TArray<uint16> HeightData;
HeightData.SetNum(SizeX * SizeY);
for (int32 i = 0; i < HeightData.Num(); i++)
{
HeightData[i] = 32768;
}
Height and material information should then be placed in the corresponding containers and be given a valid FGuid.
HeightDataPerLayers.Add(FGuid(), MoveTemp(HeightData))
MaterialLayerDataPerLayers.Add(FGuid(), MoveTemp(MaterialImportLayers))
At this point the base parameters for the landscape have been set. The ALandscape* Landscape = SpawnActor<ALandscape>() could be called at either point since it just spawns an object that doesn't actually have any information about it. This also applies for setting landscape's fields. Fields that need to be set are presented bellow:
Landscape->bCanHaveLayersContent
Landscape->LandscapeMaterial
Landscape->SetActorTransform
Landscape->StaticLightingLOD
ULandscapeInfo* LandscapeInfo = Landscape->GetLandscapeInfo()
LandscapeInfo->UpdateLayerInfoMap(Landscape)
Landscape->RegisterAllComponents()
Landscape->GetClass()
Landscape->PostEditChangeProperty(MaterialPropertyChangedEvent)
Landscape->PostEditChange()
The actual part where landscape is given form, happens with the invocation of Landscape->Import(...).
A detailed explanation about what the script could look like can be found here with more information on landscape (check the answer for the cpp code).

-Holographic Displays API- How to remove holograms near a player

I am making a plugin. That when a command is typed. It removes the nearest Holograms to the sender/player. Now, the things I have tried are to remove the Invisible armor stands in a radius of 10 blocks. I also tried to see if there is a method to get the nearest holograms, but I had no luck. If there is any way to point to what I need to do, that would be helpful. I am not asking for code, just for what I need to look under, say a specific class etc.
Thanks, seb.
Trying to remove armor stands:
for(Entity en : player.getNearbyEntities(10, 10, 10)) {
if(en instanceof ArmorStand) {
en.remove();
}
}
My Question: Where should I look to find a way to remove nearby Holograms to the player? If you can provide code, not needed though.
//Loop through all existing holograms registered to your plugin
for (Hologram hologram : HologramsAPI.getHolograms(plugin)) {
Location playerLoc = player.getLocation();
Location hologramLoc = hologram.getLocation();
//Check if the distance between the locations are less than 10
//and deletes the hologram if true
if (playerLoc.distance(hologramLoc) < 10) {
hologram.delete();
}
}
This Holographic Displays API has a hologram delete method.
https://github.com/filoghost/HolographicDisplays/wiki

What's the SDL-2.0 corresponding function for 'SDL_JoystickOpened'?

I tried to use SDL_JoystickOpened() in a SDL-2.0 code, but I got the error message SDL_JoystickOpened was not declared in this scope.
I've searched and found that SDL_JoystickOpened() no longer exists in SDL-2.0, but I didn't find the function that replaced it. Can anyone please tell me how can I replace SDL_JoystickOpened() in this piece of code:
SDL_Joystick *joy = SDL_JoystickOpen(0);
if (SDL_JoystickOpened(0) == 1)
{
// do something
}
Thanks.
The documentation says the SDL_JoystickOpen() call returns a NULL pointer if it fails so just do a check for that:
SDL_Joystick *joy = SDL_JoystickOpen(0);
if (joy) {
// joy is a valid pointer so do stuff
}
An alternative in 2.0 could be SDL_JoystickGetAttached
SDL_JoystickOpened(int index) (The old way SDL 1.2)
Determines whether a joystick has already been opened within the application. index refers to the N'th joystick on the system.
SDL_JoystickGetAttached(SDL_Joystick* joystick) (The new way SDL 2.0)
Returns SDL_TRUE if the joystick has been opened, SDL_FALSE if it has not; call SDL_GetError() for more information
There is also an example in test/testjoystick.c of SDL2 source-code (at least in SDL2-2.0.1).
Also note the Joysticks section of the SDL 1.2 to 2.0 Migration Guide. It gives various information on new features and ways in 2.0. It also links to the GameController section with e.g. SDL_GameControllerGetJoystick.

Google Maps Android API v2 getVisibleRegion() returns 0

I am using the new Google Maps Android API v2 and need to detect latlng coordinates for the corners of my screen view. I use mMap.getProjection().getVisibleRegion() to do this, which works fine the first time I load the program, but if I leave the program and then re-open it (either via the back button or the home button) getVisibleRegion() returns latlng coordinates that are all (0.0, 0.0). I have a workaround where I save the VisibleRegion object as a global in the application class when I first open the program, but this seems like a bad idea. Anyone understand why the latlng coordinates go to zero (but not null) when re-opening? Thanks!
Edit: sometimes initial load gives a (0.0, 0.0) Visible Region so my workaround is not viable. Using getProjection().fromScreenLocation(point) also returns 0.
Okay, I think I solved it: I was guessing right: The map was not visible and therefore there is also no visibleRegion (in other words a region from 0,0,0,0 to 0,0,0,0). Similar to this question
Android Google Maps API v2 calling getProjection from onResume
I attached an onCameraChanged-Listener to my map. Everytime the map is moved (or the camera is available => There is a visibleRegion) this method is called.
private void initMap() {
mMap = getMap();
if (mMap != null) {
try {
mMap.setLocationSource(this);
mMap.setOnMarkerClickListener(this);
mMap.setOnCameraChangeListener(new OnCameraChangedListener() {
#Override
public void onCameraChange(CameraPosition cameraPosition) {
Log.d(TAG, "onCameraChange");
updateMapItems();
}
}
MapsInitializer.initialize(getActivity());
...
}
}
}
This listener makes sure that you have a visibleRegion.
UPDATE: Since the new update of the Google Maps API v2, there is a callback onMapReady(). I did not use it yet, but it seems to serve exactly the purpose of this question: https://developer.android.com/reference/com/google/android/gms/maps/OnMapReadyCallback.html