great nebula effect

Previous topic - Next topic

djtoon

hi look at this


i creatd this but i cant get the part where the angel of the plane is faceing the camera

any help whold be appriciated

10x

mentalthink

Hi DJtoon, it´s very Nive the FX, I think the better way for make this effect not it´s whit planes... yes a lot of planes are very low consume of CPU, but using a couple of Spheres whit a very few polygons you can have very interenting FX, whitpout complication whit maths...

About the movement of the camera... I don´t know if can help you, the Gernnot code int the 3D part of the forum... I don´t think if billboarding can help you...

Very Nice FX !!!

FutureCow

That looks brilliant!
I'm not 100% sure what you mean by "the angle of the plane facing the camera". Are you saying you're not sure what the angle is of the current polygon relative to the camera?
3D maths is really not my strong suit (as I'm likely about to display!) but it occurs to me that if you know the position of two opposite corners and their distance from the camera, you'd end up with a triangle you may be able to calculate it from? ie. as per this page (http://www.sparknotes.com/testprep/books/sat2/math2c/chapter9section9.rhtml) a2=b2+c2-2bc*cos a or similar.

That probably doesn't help in any way, but I'm hoping it does!!!

Love the effect!

kanonet

Looks nice.
Maybe i didnt understand this right, but wouldnt using sprites/billboards be a better idea? Did you try X_SPRITE (or my Replacement)?
Lenovo Thinkpad T430u: Intel i5-3317U, 8GB DDR3, NVidia GeForce 620M, Micron RealSSD C400 @Win7 x64

djtoon

nope this is the besy way becuse when you enter the nebula you still get the 3d effect

and yes
im trying to get the angel of the plane in relation to the camera, becuse when the plane is flat it sapposed to disapear or lower alpha.

its all explaned in the move

Kitty Hello

haha. Great technique.
You need to get the angle of your polygon to the camera.
you get the matrix of the model after x_rotate.. with x_getmatrix
and the camera matrix with x_getcammatrix (or so.. look it up).

Then you need the angle difference. I'd just add (angle_dx+angle_dy+angle_dz) for that.
The angle_dx is atan2(mat[0] - cammat[0], mat[1] - cammat[1]) // or so. I don't know off my head.
the mat[0,1,2] is the direction of the X axis, where mat[4,5,6] is Y and [8,9,10] os the Z axis.

Does it help?

djtoon

well that didnt work or i just cant get the math
:(


Kitty Hello

#7
draw the textured quad in X-Y direction (X=0). Then the normal to that quad after X_ROTATION/X_MULTMATRIX would be X_GETMATIX mat[]; MakeVector(mat[8], mat[9], mat[10])

Next you need the loot-at direction vector. The easiest to get this it just to take the parameters you passed to X_CAMERA x,y,z,lx,ly,lz; The direction would be MakeVector(lx-x, ly-y, lz-z)

Now you have to vectors and only need the angle between then:
div = vector_length(v1, v2)
if div=0 then return 0
dot = vector_dot(v2, v1) / div
if dot>1 or dot<-1 then return 1 // 1.5 / 1.49999
// dot is cos(angle). So you have a value of -1 to +1 now (what you need!)
real_angle = acos(dot) // to display as text

I hope this works now.


aroldo

That is cool!
djtoon can you share your GLBasic code?
[a http://apd-games.com/][img http://apd-games.com/images/APDGames135.png][/a]
MacBook Pro OS X El Capitan
XCode Version 7
iPhone 6 running  iOS 9
iPad Mini running  iOS 7.1
Galaxy S5
Dell Latitude Windows 8 Enterprise
Palm Pre, Palm Pre2

djtoon


Kitty Hello

#10
Well - some function to make a vector to work with...
A vactor has x,y,z coordiantes.
The dot-function just does: x1*x2+y1*y2+z1*z2
The length function goes: ltot = sqr(x1*x1+y1*y1+z2*z2)

[edit] fixed former post - I forgot the div

Slydog

#11
If it helps, here's my TVector type:
(it has the Length (called 'Magnitude'), Cross Product, and Dot Product functions)

Code (glbasic) Select
//------------------------------------------------------------------ V e c t o r
TYPE TVector
x
y
z

FUNCTION Set%: x, y, z
self.x = x
self.y = y
self.z = z
ENDFUNCTION

FUNCTION Clear:
self.x = 0
self.y = 0
self.z = 0
ENDFUNCTION

FUNCTION Copy: v_from AS TVector
self.x = v_from.x
self.y = v_from.y
self.z = v_from.z
ENDFUNCTION

FUNCTION Add: v AS TVector
INC self.x, v.x
INC self.y, v.y
INC self.z, v.z
ENDFUNCTION

FUNCTION Subtract AS TVector: v1 AS TVector
LOCAL v AS TVector
v.x = self.x - v1.x
v.y = self.y - v1.y
v.z = self.z - v1.z
RETURN v
ENDFUNCTION

FUNCTION MidPoint: v1 AS TVector, v2 AS TVector
self.x = (v2.x - v1.x) / 2.0 + v1.x
self.y = (v2.y - v1.y) / 2.0 + v1.y
self.z = (v2.z - v1.z) / 2.0 + v1.z
ENDFUNCTION

FUNCTION IsEqual%: v AS TVector
IF self.x <> v.x THEN RETURN FALSE
IF self.y <> v.y THEN RETURN FALSE
IF self.z <> v.z THEN RETURN FALSE
RETURN TRUE
ENDFUNCTION

// Calc the magnitude / length of a vector
FUNCTION Magnitude:
   RETURN SQR((self.x * self.x) + (self.y * self.y) + (self.z * self.z))
ENDFUNCTION


FUNCTION Normalize:
LOCAL TOLLERANCE = 0.0001
LOCAL m
//normalize a vector so it's length = 1 AND apply tolerance based on our constant tolerance value
m = self.Magnitude()
IF m <= TOLLERANCE THEN m = 1.0
self.x = self.x / m
self.y = self.y / m
self.z = self.z / m
IF ABS(self.x) < TOLLERANCE THEN self.x = 0
IF ABS(self.y) < TOLLERANCE THEN self.y = 0
IF ABS(self.z) < TOLLERANCE THEN self.z = 0
ENDFUNCTION

// Reverse a vector
FUNCTION Reverse AS TVector:
LOCAL v AS TVector
v.x = -self.x
v.y = -self.y
v.z = -self.z
RETURN v
ENDFUNCTION

// Vector : Scalar Multiply -> used TO scale a vector by 'scale'
FUNCTION ScaleSet AS TVector: amount
   LOCAL v AS TVector
   v.x = self.x * amount
   v.y = self.y * amount
   v.z = self.z * amount
   RETURN v
ENDFUNCTION

// Vector : Scalar Divide
FUNCTION ScalarDivide: amount#
self.x = self.x / amount
self.y = self.y / amount
self.z = self.z / amount
ENDFUNCTION

// Takes v1 AND v2 AND returns the cross product v1 X v2.
// The cross product is a vector perpendicular TO both v1 AND v2
// This is the normal of 2 vectors
FUNCTION CrossProduct AS TVector: v2 AS TVector
LOCAL v AS TVector
v.x = (self.y * v2.z) - (self.z * v2.y)
v.y = (self.z * v2.x) - (self.x * v2.z)
v.z = (self.x * v2.y) - (self.y * v2.x)
RETURN v
ENDFUNCTION

// Calculate AND RETURN the dot product of 2 vectors
FUNCTION DotProduct#: v2 AS TVector
   LOCAL dp
   dp = (self.x * v2.x) + (self.y * v2.y) + (self.z * v2.z)
   RETURN dp
ENDFUNCTION

// Calculate the triple scalar FUNCTION AND RETURN it
FUNCTION TripleScalarProduct: v2 AS TVector, v3 AS TVector
   LOCAL v
   v =       self.x * ( ( v2.y * v3.z) - (v2.z * v3.y) )
   v = v + ( self.y * ( (-v2.x * v3.z) + (v2.z * v3.x) ) )
   v = v + ( self.z * ( ( v2.x * v3.y) + (v2.y * v3.x) ) )
   RETURN v
ENDFUNCTION


FUNCTION RotateAroundPointX: pivot AS TVector, angle#
LOCAL v AS TVector
LOCAL y, z, length
v.y = self.y - pivot.y
v.z = self.z - pivot.z
length = v.Magnitude()
angle = ATAN(v.z, v.y) + angle
self.y = COS(angle) * length + pivot.y
self.z = SIN(angle) * length + pivot.z
ENDFUNCTION

FUNCTION RotateAroundPointY: pivot AS TVector, angle#
LOCAL v AS TVector
LOCAL x, z, length
v.x = self.x - pivot.x
v.z = self.z - pivot.z
length = v.Magnitude()
angle = ATAN(v.z, v.x) + angle
self.x = COS(angle) * length + pivot.x
self.z = SIN(angle) * length + pivot.z
ENDFUNCTION

FUNCTION RotateAroundPointZ: pivot AS TVector, angle#
LOCAL v AS TVector
LOCAL x, y, length
v.x = self.x - pivot.x
v.y = self.y - pivot.y
length = v.Magnitude()
angle = ATAN(v.y, v.x) + angle
self.x = COS(angle) * length + pivot.x
self.y = SIN(angle) * length + pivot.y
ENDFUNCTION

FUNCTION RotateAroundVec AS TVector: v2 AS TVector, angle
LOCAL v AS TVector
LOCAL cosa, sina, ecosa
cosa = COS(angle)
sina = SIN(angle)
ecosa = 1.0 - cosa
v.x = self.x * (cosa + v2.x * v2.x * ecosa) + self.y * (v2.x * v2.y * ecosa - v2.z * sina) + self.z * (v2.x * v2.z * ecosa + v2.y * sina)
v.y = self.x * (v2.y * v2.x * ecosa + v2.z * sina) + self.y * (cosa + v2.y * v2.y * ecosa) + self.z * (v2.y * v2.z * ecosa - v2.x * sina)
v.z = self.x * (v2.z * v2.x * ecosa - v2.y * sina) + self.y * (v2.z * v2.y * ecosa + v2.x * sina) + self.z * (cosa + v2.z * v2.z * ecosa)
RETURN v
ENDFUNCTION

ENDTYPE


[Edit] Updated code to be self-contained.  It was referencing other libraries.
My current project (WIP) :: TwistedMaze <<  [Updated: 2015-11-25]

Slydog

#12
Here's how you would use it to work with Gernot's suggestions:
I had to guess in a few places, and other places I still had no idea exactly what was suggested.

Code (glbasic) Select
LOCAL v_camera AS TVector
LOCAL v_camera_look AS TVector
LOCAL v_camera_direction AS TVector
LOCAL v_quad_normal AS TVector
LOCAL v_combined AS TVector
LOCAL mat[]
LOCAL length#
LOCAL dot#
LOCAL real_angle#

// Calculate quad's normal vector
X_ROTATION 45.0, 0, 1, 0 // Set to however your quad is rotated
X_MULTMATRIX ... // not sure what to do with this
X_GETMATIX mat[]
v_quad_normal.Set(mat[8], mat[9], mat[10])


v_camera.Set(0, 0, 0)  // Camera location
v_camera_look.Set(10, 10, 10) // Camera 'Look At' point

v_camera_direction.Set(v_camera_look.x-v_camera.x, v_camera_look.y-v_camera.y, v_camera_look.z-v_camera.z)

// Place the camera
X_CAMERA v_camera.x, v_camera.y, v_camera.z,   v_camera_look.x, v_camera_look.y, v_camera_look.z

v_combined.Copy(v_camera_direction)
v_combined.Add(v_quad_normal)
length = v_combined.Magnitude() // Just guessed at this, not sure what 'vector_length(v1, v2)' meant, 'the length of both vectors combined?'
IF length = 0 THEN RETURN 0
dot = v_camera_direction.DotProduct(v_quad_normal) / length
IF (dot > 1) OR (dot < -1) THEN RETURN 1 // 1.5 / 1.49999
// dot is cos(angle). So you have a value of -1 to +1 now (what you need!)
real_angle = ACOS(dot) // to display as text
My current project (WIP) :: TwistedMaze <<  [Updated: 2015-11-25]

spicypixel

http://www.spicypixel.net | http://www.facebook.com/SpicyPixel.NET

Comps Owned - ZX.81, ZX.48K, ZX.128K+2, Vic20, C64, Atari-ST, A500.600.1200, PC, Apple Mini-Mac.

Kitty Hello

Did it work djtoon?