Trouble with Buoyancy

Hi, I’m trying to recreate these tutorials., but I can’t for the life of me figure out the C++ part.

Header


#pragma once

#include "GameFramework/Actor.h"
#include "OceanManager.generated.h"

/**
 * 
 */
UCLASS()

class WASSER_API AOceanManager : public AActor
{
	GENERATED_UCLASS_BODY()

	UFUNCTION(BlueprintCallable, Category = "HeightMap|Texture Helper")
		FVector GetWaveHeightValue(FVector location, float time);

	UFUNCTION(BlueprintCallable, Category = "HeightMap|Texture Helper")
		FVector CalculateGerstnerWaveCluster(float medianWavelength, float medianAmplitude, FVector2D position, FVector2D medianDirection, float steepness, float time);

	UFUNCTION(BlueprintCallable, Category = "HeightMap|Texture Helper")
		FVector CalculateGerstnerWave(float wavelength, float amplitude, FVector2D position, FVector2D direction, float angle, float steepness, float time, float phase);

};

CPP


#include "Wasser.h"
#include "OceanManager.h"

FVector AOceanManager::GetWaveHeightValue(FVector location, float time)
{
	FVector sum = FVector(0, 0, 0);

	sum + -CalculateGerstnerWaveCluster(1000, 10, FVector2D(location.X, location.Y), FVector2D(0, 1), 0.5f, time);
	sum + -CalculateGerstnerWaveCluster(300, 7, FVector2D(location.X, location.Y), FVector2D(0, 1), 0.5f, time);

	return sum / 2;

}

FVector AOceanManager::CalculateGerstnerWaveCluster(float medianWavelength, float medianAmplitude, FVector2D position, FVector2D medianDirection, float steepness, float time)
{

	FVector sum = FVector(0, 0, 0);

	sum + -CalculateGerstnerWave(medianWavelength, medianAmplitude, position, medianDirection, 0, steepness, time, 0);
	sum + -CalculateGerstnerWave(medianWavelength * 0.5f, medianAmplitude * 0.5f, position, medianDirection, -0.1f, steepness, time, 0);
	sum + -CalculateGerstnerWave(medianWavelength * 2.0f, medianAmplitude * 2.0f, position, medianDirection, 0.1f, steepness, time, 0);
	sum + -CalculateGerstnerWave(medianWavelength * 1.25f, medianAmplitude * 1.25f, position, medianDirection, 0.05f, steepness, time, 0);
	sum + -CalculateGerstnerWave(medianWavelength * 0.75f, medianAmplitude * 0.75f, position, medianDirection, 0.075f, steepness, time, 0);
	sum + -CalculateGerstnerWave(medianWavelength * 1.5f, medianAmplitude * 1.5f, position, medianDirection, -0.125f, steepness, time, 0);
	sum + -CalculateGerstnerWave(medianWavelength * 0.825f, medianAmplitude * 0.825f, position, medianDirection, 0.063f, steepness, time, 0);
	sum + -CalculateGerstnerWave(medianWavelength * 0.65f, medianAmplitude * 0.65f, position, medianDirection, -0.11f, steepness, time, 0);

	return sum / 8;

}

FVector AOceanManager::CalculateGerstnerWave(float wavelength, float amplitude, FVector2D position, FVector2D direction, float angle, float steepness, float time, float phase)
{
	float lambda = (2 * PI) / wavelength;

	FVector dir = FVector(direction.X, direction.Y, 0);
	dir = dir.RotateAngleAxis(angle * 360, FVector(0, 0, 1));

	FVector2D rotatedDirection = FVector2D(dir.X, dir.Y);

	float wavePhase = lambda * FVector2D::DotProduct(rotatedDirection, position) + (time + phase);

	float c = FMath::Cos(wavePhase);
	float s = FMath::Sin(wavePhase);

	float QA = steepness * amplitude;

	return FVector(QA * rotatedDirection.X * c, QA * rotatedDirection.Y *  c, amplitude * s);

}

When I try to compile, I get this error:


Error    2    error LNK2019: unresolved external symbol "public: __cdecl AOceanManager::AOceanManager(class FPostConstructInitializeProperties const &)" (??0AOceanManager@@QEAA@AEBVFPostConstructInitializeProperties@@@Z) referenced in function "void __cdecl InternalConstructor<class AOceanManager>(class FPostConstructInitializeProperties const &)" (??$InternalConstructor@VAOceanManager@@@@YAXAEBVFPostConstructInitializeProperties@@@Z)    E:\UE4Projects\Wasser\Wasser\Intermediate\ProjectFiles\Wasser.generated.cpp.obj    Wasser

I hope someone can help me.

I think you need implementation constructor for AOceanManager.



AOceanManager::AOceanManager(const class FPostConstructInitializeProperties& PCIP) : Super(PCIP)
{
}


Here are my files for reference (if you want to use them as is, then you will need to rename MyGame to your project name).

OceanFunctionLibrary.h


#pragma once

#include "OceanFunctionLibrary.generated.h"

/**
 * 
 */
UCLASS()
class **MYGAME**_API UOceanFunctionLibrary : public UBlueprintFunctionLibrary
{
	GENERATED_UCLASS_BODY()

	UFUNCTION(BlueprintCallable, Category = "Gerstner Wave")
	static void GetWaveHeight(FVector PointLocation, float Time, float WaterPlaneHeight, float& WaveHeight);

protected:
	static float CalculateGerstnerWave(float wavelength, float amplitude, FVector2D position, FVector2D direction, float angle, float steepness, float time, float phase);
	static float CalculateGerstenrWaveCluster(float medianWavelength, float medianAmplitude, FVector2D position, FVector2D medianDirection, float steepness, float time);
};

OceanFunctionLibrary.cpp


#include "**MyGame**.h"
#include "OceanFunctionLibrary.h"


UOceanFunctionLibrary::UOceanFunctionLibrary(const class FPostConstructInitializeProperties& PCIP)
	: Super(PCIP)
{
}

void UOceanFunctionLibrary::GetWaveHeight(FVector PointLocation, float Time, float WaterPlaneHeight, float& WaveHeight)
{
	float sum = 0;

	sum += CalculateGerstenrWaveCluster(2500, 200, FVector2D(PointLocation.X, PointLocation.Y), FVector2D(0, 1), 0.5f, Time);
	sum += CalculateGerstenrWaveCluster(1000, 115, FVector2D(PointLocation.X, PointLocation.Y), FVector2D(0, 1), 0.5f, Time);

	WaveHeight = sum / 2 + WaterPlaneHeight;
}

float UOceanFunctionLibrary::CalculateGerstnerWave(float wavelength, float amplitude, FVector2D position, FVector2D direction, float angle, float steepness, float time, float phase)
{
	float lambda = (2 * PI) / wavelength;

	FVector dir = FVector(direction.X, direction.Y, 0);
	dir = dir.RotateAngleAxis(angle * 360, FVector(0, 0, 1));

	FVector2D rotatedDirection = FVector2D(dir.X, dir.Y);

	float wavePhase = lambda * FVector2D::DotProduct(rotatedDirection, position) + (time + phase);
	float s = FMath::Sin(wavePhase);

	return amplitude * s;
}

float UOceanFunctionLibrary::CalculateGerstenrWaveCluster(float medianWavelength, float medianAmplitude, FVector2D position, FVector2D medianDirection, float steepness, float time)
{
	float sum = 0;

	sum += CalculateGerstnerWave(medianWavelength, medianAmplitude, position, medianDirection, 0, steepness, time, 0);
	sum += CalculateGerstnerWave(medianWavelength * 0.5f, medianAmplitude * 0.5f, position, medianDirection, -0.1f, steepness, time, 0);
	sum += CalculateGerstnerWave(medianWavelength * 2.0f, medianAmplitude * 2.0f, position, medianDirection, 0.1f, steepness, time, 0);
	sum += CalculateGerstnerWave(medianWavelength * 1.25f, medianAmplitude * 1.25f, position, medianDirection, 0.05f, steepness, time, 0);
	sum += CalculateGerstnerWave(medianWavelength * 0.75f, medianAmplitude * 0.75f, position, medianDirection, 0.075f, steepness, time, 0);
	sum += CalculateGerstnerWave(medianWavelength * 1.5f, medianAmplitude * 1.5f, position, medianDirection, -0.125f, steepness, time, 0);
	sum += CalculateGerstnerWave(medianWavelength * 0.825f, medianAmplitude * 0.825f, position, medianDirection, 0.063f, steepness, time, 0);
	sum += CalculateGerstnerWave(medianWavelength * 0.65f, medianAmplitude * 0.65f, position, medianDirection, -0.11f, steepness, time, 0);

	return sum / 8;
}

Also I noticed in your code that also calculates x and y, which is unnecessary (and slower) for buoyancy code, which you only need Z.

Thanks for the help! The code seems to be working, but now I’m getting different errors:


Error	2	error : Failed to produce item: E:\Blueprint_Lampe_Schwebe\Binaries\Win64\UE4Editor-Lampe_Reife.pdb	E:\Blueprint_Lampe_Schwebe\Intermediate\ProjectFiles\ERROR	Lampe_Reife



Error	1	error LNK1104: cannot open file 'E:\Blueprint_Lampe_Schwebe\Binaries\Win64\UE4Editor-Lampe_Reife.dll'	E:\Blueprint_Lampe_Schwebe\Intermediate\ProjectFiles\LINK	Lampe_Reife



Error	3	error MSB3073: The command ""E:\Programme\Unreal Engine\4.4\Engine\Build\BatchFiles\Build.bat" Lampe_ReifeEditor Win64 Development "E:\Blueprint_Lampe_Schwebe\Lampe_Reife.uproject" -rocket" exited with code -1.	C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V120\Microsoft.MakeFile.Targets	38	5	Lampe_Reife


My Code now:

WaterManager.h




#pragma once

#include "GameFramework/Actor.h"
#include "WaterManager.generated.h"

/**
 * 
 */
UCLASS()
class LAMPE_REIFE_API AWaterManager : public AActor
{
	GENERATED_UCLASS_BODY()

		UFUNCTION(BlueprintCallable, Category = "Gerstner Wave")
		static void GetWaveHeight(FVector PointLocation, float Time, float WaterPlaneHeight, float& WaveHeight);

protected:
	static float CalculateGerstnerWave(float wavelength, float amplitude, FVector2D position, FVector2D direction, float angle, float steepness, float time, float phase);
	static float CalculateGerstnerWaveCluster(float medianWavelength, float medianAmplitude, FVector2D position, FVector2D medianDirection, float steepness, float time);
	
};


WaterManager.cpp




#include "Lampe_Reife.h"
#include "WaterManager.h"


AWaterManager::AWaterManager(const class FPostConstructInitializeProperties& PCIP)
	: Super(PCIP)
{

}

void AWaterManager::GetWaveHeight(FVector PointLocation, float Time, float WaterPlaneHeight, float& WaveHeight)
{
	float sum = 0;

	sum += CalculateGerstnerWaveCluster(2500, 200, FVector2D(PointLocation.X, PointLocation.Y), FVector2D(0, 1), 0.5f, Time);
	sum += CalculateGerstnerWaveCluster(1000, 115, FVector2D(PointLocation.X, PointLocation.Y), FVector2D(0, 1), 0.5f, Time);

	WaveHeight = sum / 2 + WaterPlaneHeight;
}

float AWaterManager::CalculateGerstnerWave(float wavelength, float amplitude, FVector2D position, FVector2D direction, float angle, float steepness, float time, float phase)
{
	float lambda = (2 * PI) / wavelength;

	FVector dir = FVector(direction.X, direction.Y, 0);
	dir = dir.RotateAngleAxis(angle * 360, FVector(0, 0, 1));

	FVector2D rotatedDirection = FVector2D(dir.X, dir.Y);

	float wavePhase = lambda * FVector2D::DotProduct(rotatedDirection, position) + (time + phase);
	float s = FMath::Sin(wavePhase);

	return amplitude * s;
}

float AWaterManager::CalculateGerstnerWaveCluster(float medianWavelength, float medianAmplitude, FVector2D position, FVector2D medianDirection, float steepness, float time)
{
	float sum = 0;

	sum += CalculateGerstnerWave(medianWavelength, medianAmplitude, position, medianDirection, 0, steepness, time, 0);
	sum += CalculateGerstnerWave(medianWavelength * 0.5f, medianAmplitude * 0.5f, position, medianDirection, -0.1f, steepness, time, 0);
	sum += CalculateGerstnerWave(medianWavelength * 2.0f, medianAmplitude * 2.0f, position, medianDirection, 0.1f, steepness, time, 0);
	sum += CalculateGerstnerWave(medianWavelength * 1.25f, medianAmplitude * 1.25f, position, medianDirection, 0.05f, steepness, time, 0);
	sum += CalculateGerstnerWave(medianWavelength * 0.75f, medianAmplitude * 0.75f, position, medianDirection, 0.075f, steepness, time, 0);
	sum += CalculateGerstnerWave(medianWavelength * 1.5f, medianAmplitude * 1.5f, position, medianDirection, -0.125f, steepness, time, 0);
	sum += CalculateGerstnerWave(medianWavelength * 0.825f, medianAmplitude * 0.825f, position, medianDirection, 0.063f, steepness, time, 0);
	sum += CalculateGerstnerWave(medianWavelength * 0.65f, medianAmplitude * 0.65f, position, medianDirection, -0.11f, steepness, time, 0);

	return sum / 8;
}