Announcement

Collapse
No announcement yet.

Playing with Physics, where to start?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Playing with Physics, where to start?

    ey up

    just out of curiosity, i want to start messing with physics. all the info i have found is about blueprints and mainly about constraining 2 actors together.
    however i would like to dig into the core of physx simulation and see what craziness i can come up with.

    so very generally, what areas of the source are interesting to play with?
    are there any c++ examples around i could take a look at?

    thanks
    sorry about the vagueness
    tegleg.co.uk - indie electronic music label
    Android + HTML5 WIP Physics Game
    PC Games - Android Apps

    #2
    I guess this is a good place to start.
    https://wiki.unrealengine.com/PhysX,...o_Your_Project

    Maybe i could be of more help if you explain a litle futher what you are thinking about doing.
    WCode.

    Comment


      #3
      that is a good place to start thanks

      no end goal in mind, i just want to have a play with it
      tegleg.co.uk - indie electronic music label
      Android + HTML5 WIP Physics Game
      PC Games - Android Apps

      Comment


        #4
        oh dear, other than #include "PhysXIncludes.h" every line of that code throws errors
        guess it was for an earlier engine version
        tegleg.co.uk - indie electronic music label
        Android + HTML5 WIP Physics Game
        PC Games - Android Apps

        Comment


          #5
          Originally posted by tegleg View Post
          oh dear, other than #include "PhysXIncludes.h" every line of that code throws errors
          guess it was for an earlier engine version
          Did you include the modules for it?
          In YourProjectName.Build.cs
          Code:
          PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore", "PhysX", "APEX"});
          If it do not solve the issue, please post the error messages you are getting.
          WCode
          Last edited by WCode; 11-13-2014, 07:06 PM. Reason: spelling

          Comment


            #6
            yep i did
            im using 4.6 and a lot of stuff seems to have changed (so im guessing from the error comments)

            heres the errors
            Code:
            1>C:\Users\bob\Documents\Unreal Projects\PhysicsMess\Source\PhysicsMess\Public\MyDestructibleActor.h(28): error C3861: 'DrawDebugPoint': identifier not found
            1>C:\Users\bob\Documents\Unreal Projects\PhysicsMess\Source\PhysicsMess\Public\MyDestructibleActor.h(40): error C2065: 'GEngine' : undeclared identifier
            1>C:\Users\bob\Documents\Unreal Projects\PhysicsMess\Source\PhysicsMess\Public\MyDestructibleActor.h(40): error C2227: left of '->AddOnScreenDebugMessage' must point to class/struct/union/generic type
            1>          type is 'unknown-type'
            1>C:\Users\bob\Documents\Unreal Projects\PhysicsMess\Source\PhysicsMess\Public\MyDestructibleActor.h(45): error C2065: 'GEngine' : undeclared identifier
            1>C:\Users\bob\Documents\Unreal Projects\PhysicsMess\Source\PhysicsMess\Public\MyDestructibleActor.h(45): error C2227: left of '->AddOnScreenDebugMessage' must point to class/struct/union/generic type
            1>          type is 'unknown-type'
            1>C:\Users\bob\Documents\Unreal Projects\PhysicsMess\Source\PhysicsMess\Public/MyDestructibleActor.h(28): error C3861: 'DrawDebugPoint': identifier not found
            1>C:\Users\bob\Documents\Unreal Projects\PhysicsMess\Source\PhysicsMess\Public/MyDestructibleActor.h(40): error C2065: 'GEngine' : undeclared identifier
            1>C:\Users\bob\Documents\Unreal Projects\PhysicsMess\Source\PhysicsMess\Public/MyDestructibleActor.h(40): error C2227: left of '->AddOnScreenDebugMessage' must point to class/struct/union/generic type
            1>          type is 'unknown-type'
            1>C:\Users\bob\Documents\Unreal Projects\PhysicsMess\Source\PhysicsMess\Public/MyDestructibleActor.h(45): error C2065: 'GEngine' : undeclared identifier
            1>C:\Users\bob\Documents\Unreal Projects\PhysicsMess\Source\PhysicsMess\Public/MyDestructibleActor.h(45): error C2227: left of '->AddOnScreenDebugMessage' must point to class/struct/union/generic type
            1>          type is 'unknown-type'
            1>C:\Users\bob\Documents\Unreal Projects\PhysicsMess\Source\PhysicsMess\Private\MyDestructibleActor.cpp(10): warning C4996: FPostConstructInitializeProperties is deprecated and was renamed to FObjectInitializer. Please use that type instead.
            1>C:\Users\bob\Documents\Unreal Projects\PhysicsMess\Source\PhysicsMess\Private\MyDestructibleActor.cpp(10): error C2084: function 'AMyDestructibleActor::AMyDestructibleActor(const FObjectInitializer &)' already has a body
            1>          C:\Users\bob\Documents\Unreal Projects\PhysicsMess\Source\PhysicsMess\Public\MyDestructibleActor.h(14) : see previous definition of '{ctor}'
            1>C:\Users\bob\Documents\Unreal Projects\PhysicsMess\Source\PhysicsMess\Private\MyDestructibleActor.cpp(24): warning C4996: 'ADestructibleActor::DestructibleComponent': DestructibleComponent should not be accessed directly, please use GetDestructibleComponent() function instead. DestructibleComponent will soon be private and your code will not compile. Please update your code to the new API before upgrading to the next release, otherwise your project will no longer compile.
            1>          D:\GitHub\UnrealEngine-4.6\Engine\Source\Runtime\Engine\Classes\PhysicsEngine/DestructibleActor.h(25) : see declaration of 'ADestructibleActor::DestructibleComponent'
            1>C:\Users\bob\Documents\Unreal Projects\PhysicsMess\Source\PhysicsMess\Private\MyDestructibleActor.cpp(24): error C2027: use of undefined type 'UDestructibleComponent'
            1>          D:\GitHub\UnrealEngine-4.6\Engine\Source\Runtime\Engine\Classes\PhysicsEngine/DestructibleActor.h(9) : see declaration of 'UDestructibleComponent'
            1>C:\Users\bob\Documents\Unreal Projects\PhysicsMess\Source\PhysicsMess\Private\MyDestructibleActor.cpp(24): error C2227: left of '->ChunkInfos' must point to class/struct/union/generic type
            1>C:\Users\bob\Documents\Unreal Projects\PhysicsMess\Source\PhysicsMess\Private\MyDestructibleActor.cpp(26): error C2065: 'Each' : undeclared identifier
            1>C:\Users\bob\Documents\Unreal Projects\PhysicsMess\Source\PhysicsMess\Private\MyDestructibleActor.cpp(26): error C2228: left of '.Actor' must have class/struct/union
            1>          type is 'unknown-type'
            1>  -------- End Detailed Actions Stats -----------------------------------------------------------
            here is my code just incase im a complete spaz and cant copy/paste/edit or something
            'PHYSICSMESS_API' was generated by ue4 when i added the class from the editor, i just added the content from the wiki page
            .h
            Code:
            // Fill out your copyright notice in the Description page of Project Settings.
            
            #pragma once
            
            #include "PhysicsEngine/DestructibleActor.h"
            #include "MyDestructibleActor.generated.h"
            
            /**
             * 
             */
            UCLASS()
            class PHYSICSMESS_API AMyDestructibleActor : public ADestructibleActor
            {
            	GENERATED_BODY()
            	
            protected:
            	virtual void Tick(float DeltaTime) override;
            
            	//Drawing!
            public:
            	FORCEINLINE void DrawPoint
            		(
            		const FVector& Loc,
            		const float& Size = 7,
            		const FColor& Color = FColor::Red,
            		const float Duration = -1.f
            		) const {
            		DrawDebugPoint(
            			GetWorld(),
            			Loc,
            			Size, //thickness
            			Color,
            			false,
            			Duration
            			);
            	}
            
            	FORCEINLINE void ScreenMsg(const FString& Msg)
            	{
            		GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, *Msg);
            	}
            
            	FORCEINLINE void ScreenMsg(const FString& Msg, const FString& Msg2)
            	{
            		GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, FString::Printf(TEXT("%s %s"), *Msg, *Msg2));
            	}
            };
            .cpp
            Code:
            // Fill out your copyright notice in the Description page of Project Settings.
            
            #include "PhysicsMess.h"
            #include "MyDestructibleActor.h"
            //~~~~~~~~~~~~~~~~~~~~~~~~
            //	   PhysX 			
            #include "PhysXIncludes.h" 
            //~~~~~~~~~~~~~~~~~~~~~~~~
            
            AMyDestructibleActor::AMyDestructibleActor(const class FPostConstructInitializeProperties& PCIP) : Super(PCIP)
            {
            
            }
            //Tick
            void AMyDestructibleActor::Tick(float DeltaTime)
            {
            	Super::Tick(DeltaTime);
            	//~~~~~~~~~~~~
            
            
            	//Draw All Centers to the screen!
            #if WITH_PHYSX
            	ScreenMsg("Got into PhysX!!!");
            	for (FDestructibleChunkInfo& Each : DestructibleComponent->ChunkInfos)
            	{
            		physx::PxRigidDynamic* Actor = Each.Actor;
            
            		if (Actor)
            		{
            			PxTransform Trans = Actor->getGlobalPose();
            			PxVec3& PxLoc = Trans.p;
            
            			FVector Location(PxLoc.x, PxLoc.y, PxLoc.z);
            
            			DrawPoint(Location);
            
            			ScreenMsg("physx loc", Location.ToString());
            		}
            	}
            #endif // WITH_PHYSX 
            }
            Last edited by tegleg; 11-13-2014, 07:22 PM.
            tegleg.co.uk - indie electronic music label
            Android + HTML5 WIP Physics Game
            PC Games - Android Apps

            Comment


              #7
              check the main header file of your project. for example mine is just Elium.h

              change
              #include "EngineMinimal.h"
              to
              #include "Engine.h"

              this changed in 4.4 IIRC

              and yes, this is one of those things you only find about by browsing AnswerHub
              Follow me on Twitter!
              Developer of Elium - Prison Escape
              Local Image-Based Lighting for UE4

              Comment


                #8
                well that certainly cut down the errors thanks,
                however
                Code:
                1>C:\Users\bob\Documents\Unreal Projects\PhysicsMess\Source\PhysicsMess\Private\MyDestructibleActor.cpp(10): warning C4996: FPostConstructInitializeProperties is deprecated and was renamed to FObjectInitializer. Please use that type instead.
                1>C:\Users\bob\Documents\Unreal Projects\PhysicsMess\Source\PhysicsMess\Private\MyDestructibleActor.cpp(10): error C2084: function 'AMyDestructibleActor::AMyDestructibleActor(const FObjectInitializer &)' already has a body
                1>          C:\Users\bob\Documents\Unreal Projects\PhysicsMess\Source\PhysicsMess\Public\MyDestructibleActor.h(14) : see previous definition of '{ctor}'
                1>C:\Users\bob\Documents\Unreal Projects\PhysicsMess\Source\PhysicsMess\Private\MyDestructibleActor.cpp(24): warning C4996: 'ADestructibleActor::DestructibleComponent': DestructibleComponent should not be accessed directly, please use GetDestructibleComponent() function instead. DestructibleComponent will soon be private and your code will not compile. Please update your code to the new API before upgrading to the next release, otherwise your project will no longer compile.
                1>          D:\GitHub\UnrealEngine-4.6\Engine\Source\Runtime\Engine\Classes\PhysicsEngine/DestructibleActor.h(25) : see declaration of 'ADestructibleActor::DestructibleComponent'
                1>          D:\GitHub\UnrealEngine-4.6\Engine\Source\Runtime\Engine\Classes\PhysicsEngine/DestructibleActor.h(25) : see declaration of 'ADestructibleActor::DestructibleComponent'
                1>  -------- End Detailed Actions Stats -----------------------------------------------------------
                edit:
                after fixing those errors it compiles!!!

                here is the .cpp that compiles
                Code:
                // Fill out your copyright notice in the Description page of Project Settings.
                
                #include "PhysicsMess.h"
                #include "MyDestructibleActor.h"
                //~~~~~~~~~~~~~~~~~~~~~~~~
                //	   PhysX 			
                #include "PhysXIncludes.h" 
                //~~~~~~~~~~~~~~~~~~~~~~~~
                
                //Tick
                void AMyDestructibleActor::Tick(float DeltaTime)
                {
                	Super::Tick(DeltaTime);
                	//~~~~~~~~~~~~
                
                
                	//Draw All Centers to the screen!
                #if WITH_PHYSX
                	ScreenMsg("Got into PhysX!!!");
                	for (FDestructibleChunkInfo& Each : GetDestructibleComponent()->ChunkInfos)
                	{
                		physx::PxRigidDynamic* Actor = Each.Actor;
                
                		if (Actor)
                		{
                			PxTransform Trans = Actor->getGlobalPose();
                			PxVec3& PxLoc = Trans.p;
                
                			FVector Location(PxLoc.x, PxLoc.y, PxLoc.z);
                
                			DrawPoint(Location);
                
                			ScreenMsg("physx loc", Location.ToString());
                		}
                	}
                #endif // WITH_PHYSX 
                }
                thanks ever so much for the help
                Last edited by tegleg; 11-13-2014, 07:37 PM.
                tegleg.co.uk - indie electronic music label
                Android + HTML5 WIP Physics Game
                PC Games - Android Apps

                Comment

                Working...
                X